cvs: phpdoc-da /reference/strings/functions sprintf.xml

From: Date: Sun, 01 Aug 2004 11:50:42 +0000
Subject: cvs: phpdoc-da /reference/strings/functions sprintf.xml
Groups: php.doc.da 
Request: Send a blank email to doc-da+get-163@lists.php.net to get a copy of this message
holst Sun Aug 1 07:50:42 2004 EDT Modified files: /phpdoc-da/reference/strings/functions sprintf.xml Log: Sync with EN http://cvs.php.net/diff.php/phpdoc-da/reference/strings/functions/sprintf.xml?r1=1.3&r2=1.4&ty=u Index: phpdoc-da/reference/strings/functions/sprintf.xml diff -u phpdoc-da/reference/strings/functions/sprintf.xml:1.3 phpdoc-da/reference/strings/functions/sprintf.xml:1.4 --- phpdoc-da/reference/strings/functions/sprintf.xml:1.3 Sun Aug 1 07:23:11 2004 +++ phpdoc-da/reference/strings/functions/sprintf.xml Sun Aug 1 07:50:41 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <!-- EN-Revision: 1.10 Maintainer: holst Status: ready --> <refentry id="function.sprintf"> <refnamediv> @@ -186,44 +186,114 @@ </refsect1> <refsect1> <title>Eksempler</title> - <para> - <example> - <title><function>sprintf</function>: nul-udstoppede heltal</title> - <programlisting role="php"> + <example> + <title><function>printf</function>: forskellige eksempler</title> + <programlisting role="php"> +<![CDATA[ +<?php +$n = 43951789; +$u = -43951789; +$c = 65; // ASCII 65 er 'A' + +// bemærk de dobbelte %%, de udkskriver et enkelt '%' +printf("%%b = '%b'\n", $n); // binær præsentation +printf("%%c = '%c'\n", $c); // print asciitegnet, samme som chr() +function +printf("%%d = '%d'\n", $n); // standard heltalspræsentation +printf("%%e = '%e'\n", $n); // videnskabelig tegnsætning +printf("%%u = '%u'\n", $n); // usigneret heltalspræsentation af et positivt +heltal +printf("%%u = '%u'\n", $u); // usigneret heltalspræsentation af et negativt +heltal +printf("%%f = '%f'\n", $n); // kommatalspræsentation +printf("%%o = '%o'\n", $n); // oktal præsentation +printf("%%s = '%s'\n", $n); // strengpræsentation +printf("%%x = '%x'\n", $n); // hexadecimal præsentation (små bogstaver) +printf("%%X = '%X'\n", $n); // hexadecimal præsentation (store bogstaver) +?> +]]> + </programlisting> + <para> + Resultatet af dette program ville være: + </para> + <screen> +<![CDATA[ +%b = '10100111101010011010101101' +%c = 'A' +%d = '43951789' +%e = '4.39518e+7' +%u = '43951789' +%u = '4251015507' +%f = '43951789.000000' +%o = '247523255' +%s = '43951789' +%x = '29ea6ad' +%X = '29EA6AD' ++]]> + </screen> + </example> + <example> + <title><function>printf</function>: strengspecifikatorer</title> + <programlisting role="php"> +<![CDATA[ +<?php +$s = 'abe'; +$t = 'rigtigt mange aber'; + +printf("[%s]\n", $s); // standard strengudskrift +printf("[%10s]\n", $s); // højrestillet med mellemrum +printf("[%-10s]\n", $s); // venstrestillet med mellemrum +printf("[%010s]\n", $s); // nuludfyldning virker også på strenge +printf("[%10.10s]\n", $t); // venstrestillet, men afskåret ved 10 tegn +?> +]]> + </programlisting> + <para> + Resultatet af dette program ville være: + </para> + <screen> +<![CDATA[ +[abe] +[ abe] +[abe ] +[0000000abe] +[rigtige ma] +]]> + </screen> + </example> + <example> + <title><function>sprintf</function>: nuludfyldte heltal</title> + <programlisting role="php"> <![CDATA[ <?php $isodate = sprintf("%04d-%02d-%02d", $year, $month, $day); ?> ]]> - </programlisting> - </example> - <example> - <title><function>sprintf</function>: formaterer valuta</title> - <programlisting role="php"> + </programlisting> + </example> + <example> + <title><function>sprintf</function>: formater valuta</title> + <programlisting role="php"> <![CDATA[ <?php $money1 = 68.75; -$money2 = 54.35; -$money = $money1 + $money2; -// echo $money vil udskrive "123.1"; -$formatted = sprintf("%01.2f", $money); -// echo $formatted vil udskrive "123.10" +$formatted = sprintf("%01.2f", $money1); // echo $formatted ville udskrive +"123.10" ?> ]]> </programlisting> </example> - <example> - <title><function>sprintf</function>: videnskabeligt tegnsystem</title> - <programlisting role="php"> + <example> + <title><function>sprintf</function>: videnskabeligt tegnsystem</title> + <programlisting role="php"> <![CDATA[ <?php $number = 362525200; - echo sprintf("%.3e", $number); // udskriver 3.63e+8 ?> ]]> - </programlisting> - </example> + </programlisting> + </example> </para> </refsect1> </refentry>

« previous php.doc.da (#163) next »