cvs: phpdoc /en/language/types string.xml /en/reference/array/functions uasort.xml /en/reference/datetime/datetimezone construct.xml
/en/reference/filesystem/functions file-get-contents.xml file-put-contents.xml /en/reference/info/functions ini-set.xml

From: Date: Mon, 09 Feb 2009 21:54:29 +0000
Subject: cvs: phpdoc /en/language/types string.xml /en/reference/array/functions uasort.xml /en/reference/datetime/datetimezone construct.xml
/en/reference/filesystem/functions file-get-contents.xml file-put-contents.xml /en/reference/info/functions ini-set.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-3174@lists.php.net to get a copy of this message
ross Mon Feb 9 21:54:29 2009 UTC Modified files: /phpdoc/en/language/types string.xml /phpdoc/en/reference/array/functions uasort.xml /phpdoc/en/reference/datetime/datetimezone construct.xml /phpdoc/en/reference/filesystem/functions file-get-contents.xml file-put-contents.xml /phpdoc/en/reference/info/functions ini-set.xml Log: * Fix for http://news.php.net/php.webmaster/3784 * Examples for uasort, DateTimeZone::construct, file_get_contents, file_put_contents and ini_set

http://cvs.php.net/viewvc.cgi/phpdoc/en/language/types/string.xml?r1=1.17&r2=1.18&diff_format=u Index: phpdoc/en/language/types/string.xml diff -u phpdoc/en/language/types/string.xml:1.17 phpdoc/en/language/types/string.xml:1.18 --- phpdoc/en/language/types/string.xml:1.17 Wed Jan 7 15:54:35 2009 +++ phpdoc/en/language/types/string.xml Mon Feb 9 21:54:29 2009 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- $Revision: 1.17 $ --> +<!-- $Revision: 1.18 $ --> <sect1 xml:id="language.types.string"> <title>Strings</title> @@ -534,7 +534,7 @@ <simpara> In fact, any value in the namespace can be included in a <type>string</type> with this syntax. Simply write the expression the same - way as it would appeared outside the <type>string</type>, and then wrap it + way as it would have appeared outside the <type>string</type>, and then wrap it in <literal>{</literal> and <literal>}</literal>. Since <literal>{</literal> can not be escaped, this syntax will only be recognised when the <literal>$</literal> immediately follows the http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/array/functions/uasort.xml?r1=1.11&r2=1.12&diff_format=u Index: phpdoc/en/reference/array/functions/uasort.xml diff -u phpdoc/en/reference/array/functions/uasort.xml:1.11 phpdoc/en/reference/array/functions/uasort.xml:1.12 --- phpdoc/en/reference/array/functions/uasort.xml:1.11 Sun Dec 30 11:35:34 2007 +++ phpdoc/en/reference/array/functions/uasort.xml Mon Feb 9 21:54:29 2009 @@ -1,10 +1,11 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.11 $ --> +<!-- $Revision: 1.12 $ --> <refentry xml:id="function.uasort" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>uasort</refname> <refpurpose>Sort an array with a user-defined comparison function and maintain index association</refpurpose> </refnamediv> + <refsect1 role="description"> &reftitle.description; <methodsynopsis> @@ -22,6 +23,7 @@ element order is significant. </para> </refsect1> + <refsect1 role="parameters"> &reftitle.parameters; <para> @@ -46,12 +48,71 @@ </variablelist> </para> </refsect1> + <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> + + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Basic <function>uasort</function> example</title> + <programlisting role="php"> +<![CDATA[ +<?php +// Comparison function +function cmp($a, $b) { + if ($a == $b) { + return 0; + } + return ($a < $b) ? -1 : 1; +} + +// Array to be sorted +$array = array('a' => 4, 'b' => 8, 'c' => -1, 'd' => -9, 'e' => 2, 'f' => 5, 'g' => 3, 'h' => -4); +print_r($array); + +// Sort and print the resulting array +uasort($array, 'cmp'); +print_r($array); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +Array +( + [a] => 4 + [b] => 8 + [c] => -1 + [d] => -9 + [e] => 2 + [f] => 5 + [g] => 3 + [h] => -4 +) +Array +( + [d] => -9 + [h] => -4 + [c] => -1 + [e] => 2 + [g] => 3 + [a] => 4 + [f] => 5 + [b] => 8 +) +]]> + </screen> + </example> + </para> + </refsect1> + <refsect1 role="seealso"> &reftitle.seealso; <para> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/datetime/datetimezone/construct.xml?r1=1.1&r2=1.2&diff_format=u Index: phpdoc/en/reference/datetime/datetimezone/construct.xml diff -u phpdoc/en/reference/datetime/datetimezone/construct.xml:1.1 phpdoc/en/reference/datetime/datetimezone/construct.xml:1.2 --- phpdoc/en/reference/datetime/datetimezone/construct.xml:1.1 Tue Jan 6 14:54:59 2009 +++ phpdoc/en/reference/datetime/datetimezone/construct.xml Mon Feb 9 21:54:29 2009 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry xml:id="datetimezone.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> <refnamediv> @@ -33,6 +33,53 @@ </variablelist> </para> </refsect1> + + <refsect1 role="returnvalues"> + &reftitle.returnvalues; + <para> + Returns <classname>DateTimeZone</classname> on success. + </para> + </refsect1> + + <refsect1 role="errors"> + &reftitle.errors; + <para> + This method throws <classname>Exception</classname> if the timezone supplied is not + recognised as a valid timezone. + </para> + </refsect1> + + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Catching errors when instantiating <classname>DateTimeZone</classname></title> + <programlisting role="php"> +<![CDATA[ +<?php +// Error handling by catching exceptions +$timezones = array('Europe/London', 'Mars/Phobos', 'Jupiter/Europa'); + +foreach ($timezones as $tz) { + try { + $mars = new DateTimeZone($tz); + } catch(Exception $e) { + echo $e->getMessage() . '<br />'; + } +} +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos) +DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa) +]]> + </screen> + </example> + </para> + </refsect1> </refentry> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/filesystem/functions/file-get-contents.xml?r1=1.33&r2=1.34&diff_format=u Index: phpdoc/en/reference/filesystem/functions/file-get-contents.xml diff -u phpdoc/en/reference/filesystem/functions/file-get-contents.xml:1.33 phpdoc/en/reference/filesystem/functions/file-get-contents.xml:1.34 --- phpdoc/en/reference/filesystem/functions/file-get-contents.xml:1.33 Fri Jan 16 16:14:25 2009 +++ phpdoc/en/reference/filesystem/functions/file-get-contents.xml Mon Feb 9 21:54:29 2009 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.33 $ --> +<!-- $Revision: 1.34 $ --> <refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.file-get-contents"> <refnamediv> <refname>file_get_contents</refname> @@ -154,6 +154,76 @@ </para> </refsect1> + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Get and output the source of the PHP.net homepage</title> + <programlisting role="php"> +<![CDATA[ +<?php +$homepage = file_get_contents('http://www.example.com/'); +echo $homepage; +?> +]]> + </programlisting> + </example> + <example> + <title>Searching within the include_path</title> + <programlisting role="php"> +<![CDATA[ +<?php +// <= PHP 5 +$file = file_get_contents('./people.txt', true); +// > PHP 5 +$file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH); +?> +]]> + </programlisting> + </example> + <example> + <title>Reading a section of a file</title> + <programlisting role="php"> +<![CDATA[ +<?php +// Read 50 characters from the 100th character +$section = file_get_contents('./people.txt', NULL, NULL, 20, 14); +var_dump($section); +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +string(14) "lle Bjori Ro" +]]> + </screen> + </example> + <example> + <title>Using stream contexts</title> + <programlisting role="php"> +<![CDATA[ +<?php +// Create a stream +$opts = array( + 'http'=>array( + 'method'=>"GET", + 'header'=>"Accept-language: en\r\n" . + "Cookie: foo=bar\r\n" + ) +); + +$context = stream_context_create($opts); + +// Open the file using the HTTP headers set above +$file = file_get_contents('http://www.example.com/', false, $context); +?> +]]> + </programlisting> + </example> + </para> + </refsect1> + <refsect1 role="changelog"> &reftitle.changelog; <para> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/filesystem/functions/file-put-contents.xml?r1=1.24&r2=1.25&diff_format=u Index: phpdoc/en/reference/filesystem/functions/file-put-contents.xml diff -u phpdoc/en/reference/filesystem/functions/file-put-contents.xml:1.24 phpdoc/en/reference/filesystem/functions/file-put-contents.xml:1.25 --- phpdoc/en/reference/filesystem/functions/file-put-contents.xml:1.24 Fri Jan 16 16:14:25 2009 +++ phpdoc/en/reference/filesystem/functions/file-put-contents.xml Mon Feb 9 21:54:29 2009 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.24 $ --> +<!-- $Revision: 1.25 $ --> <refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.file-put-contents"> <refnamediv> <refname>file_put_contents</refname> @@ -157,6 +157,68 @@ </para> </refsect1> + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Simple usage example</title> + <programlisting role="php"> +<![CDATA[ +<?php +$file = 'people.txt'; +// Open the file to get existing content +$current = file_get_contents($file); +// Append a new person to the file +$current .= "John Smith\n"; +// Write the contents back to the file +file_put_contents($file, $current); +?> +]]> + </programlisting> + </example> + <example> + <title>Using flags</title> + <programlisting role="php"> +<![CDATA[ +<?php +$file = 'people.txt'; +// The new person to add to the file +$person = "John Smith\n"; +// Write the contents to the file, +// using the FILE_APPEND flag to append the content to the end of the file +// and the LOCK_EX flag to prevent anyone else writing to the file at the same time +file_put_contents($file, $person, FILE_APPEND | LOCK_EX); +?> +]]> + </programlisting> + </example> + <example> + <title>Using stream contexts</title> + <programlisting role="php"> +<![CDATA[ +<?php +// Create a stream +$opts = array( + 'http'=>array( + 'method'=>"GET", + 'header'=>"Accept-language: en\r\n" . + "Cookie: foo=bar\r\n" + ) +); + +$context = stream_context_create($opts); + +$person = "John Smith\n"; + +// Add content to the file using the HTTP headers set above +file_put_contents('people.txt', $person, NULL, $context); +?> +]]> + </programlisting> + </example> + </para> + </refsect1> + <refsect1 role="changelog"> &reftitle.changelog; <para> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/info/functions/ini-set.xml?r1=1.49&r2=1.50&diff_format=u Index: phpdoc/en/reference/info/functions/ini-set.xml diff -u phpdoc/en/reference/info/functions/ini-set.xml:1.49 phpdoc/en/reference/info/functions/ini-set.xml:1.50 --- phpdoc/en/reference/info/functions/ini-set.xml:1.49 Wed Jun 20 22:24:47 2007 +++ phpdoc/en/reference/info/functions/ini-set.xml Mon Feb 9 21:54:29 2009 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.49 $ --> +<!-- $Revision: 1.50 $ --> <refentry xml:id="function.ini-set" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>ini_set</refname> @@ -55,6 +55,28 @@ </para> </refsect1> + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title>Setting an ini option</title> + <programlisting role="php"> +<![CDATA[ +<?php +echo ini_get('display_errors'); + +if (!ini_get('display_errors')) { + ini_set('display_errors', 1); +} + +echo ini_get('display_errors'); +?> +]]> + </programlisting> + </example> + </para> + </refsect1> + <refsect1 role="seealso"> &reftitle.seealso; <para>
« previous php.doc.cvs (#3174) next »