<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://wbex.ru/index.php?action=history&amp;feed=atom&amp;title=PHP%2FString%2Fsprintf</id>
		<title>PHP/String/sprintf - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://wbex.ru/index.php?action=history&amp;feed=atom&amp;title=PHP%2FString%2Fsprintf"/>
		<link rel="alternate" type="text/html" href="http://wbex.ru/index.php?title=PHP/String/sprintf&amp;action=history"/>
		<updated>2026-04-05T04:02:06Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://wbex.ru/index.php?title=PHP/String/sprintf&amp;diff=1290&amp;oldid=prev</id>
		<title> в 10:37, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://wbex.ru/index.php?title=PHP/String/sprintf&amp;diff=1290&amp;oldid=prev"/>
				<updated>2010-05-26T10:37:30Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 10:37, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://wbex.ru/index.php?title=PHP/String/sprintf&amp;diff=1291&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://wbex.ru/index.php?title=PHP/String/sprintf&amp;diff=1291&amp;oldid=prev"/>
				<updated>2010-05-26T07:07:26Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==integer displayed as a dollar amount set to two decimal places==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;?php &lt;br /&gt;
    $thenumber = 9.99 * 1.07; &lt;br /&gt;
    echo &amp;quot;$&amp;quot; . $thenumber . &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;; &lt;br /&gt;
    echo &amp;quot;$&amp;quot; . sprintf (&amp;quot;%.2f&amp;quot;, $thenumber); &lt;br /&gt;
?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Integral that the value be displayed as a dollar amount set to two decimal places:==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
  $thenumber = 9.99 * 1.07;&lt;br /&gt;
  echo &amp;quot;$&amp;quot; . $thenumber . &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;; &lt;br /&gt;
  echo &amp;quot;$&amp;quot; . sprintf (&amp;quot;%.2f&amp;quot;, $thenumber); &lt;br /&gt;
?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==sprintf print values to a string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$cost = sprintf(&amp;quot;$%01.2f&amp;quot;, 43.2); &lt;br /&gt;
echo $cost;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==sprintf()&amp;quot;s built-in hex-to-decimal conversion with the %x format character==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
function build_color($red, $green, $blue) {&lt;br /&gt;
    return sprintf(&amp;quot;#%02x%02x%02x&amp;quot;, $red, $green, $blue);&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Storing a Formatted String==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$dosh = sprintf(&amp;quot;%.2f&amp;quot;, 2.334454);&lt;br /&gt;
print &amp;quot;$dosh dollars&amp;quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using a sprintf()-style message catalog==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$LANG = &amp;quot;es_US&amp;quot;;&lt;br /&gt;
print sprintf(msg(&amp;quot;I am X years old.&amp;quot;),12);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using sprintf() to ensure that one digit hex numbers (like 0) get padded with a leading 0.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
function build_color($red, $green, $blue) {&lt;br /&gt;
    $redhex   = dechex($red);&lt;br /&gt;
    $greenhex = dechex($green);&lt;br /&gt;
    $bluehex  = dechex($blue);&lt;br /&gt;
    return sprintf(&amp;quot;#%02s%02s%02s&amp;quot;, $redhex, $greenhex, $bluehex);&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using sprintf with a variable==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$total = sprintf(&amp;quot;Please pay $%.2f. &amp;quot;, 42.4242 );&lt;br /&gt;
echo $total;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Wrap these in a couple of functions and surround the joined array elements with parentheses==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;?php &lt;br /&gt;
function array_values_string($arr) { &lt;br /&gt;
    return sprintf(&amp;quot;(%s)&amp;quot;, implode(&amp;quot;, &amp;quot;, array_values($arr))); &lt;br /&gt;
} &lt;br /&gt;
function array_keys_string($arr){ &lt;br /&gt;
    return sprintf(&amp;quot;(%s)&amp;quot;, implode(&amp;quot;, &amp;quot;, array_key($arr))); &lt;br /&gt;
} &lt;br /&gt;
$countries_languages = array(&amp;quot;Germany&amp;quot; =&amp;gt; &amp;quot;German&amp;quot;, &amp;quot;France&amp;quot; =&amp;gt; &amp;quot;French&amp;quot;, &amp;quot;Spain&amp;quot; =&amp;gt; &amp;quot;Spanish&amp;quot;); &lt;br /&gt;
print &amp;quot;Countries: &amp;quot;; &lt;br /&gt;
print array_keys_string($countries_languages); &lt;br /&gt;
print &amp;quot;&amp;lt;br /&amp;gt;Languages: &amp;quot;; &lt;br /&gt;
print array_values_string($countries_languages); &lt;br /&gt;
?&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>