php-doc-en/reference/strings/functions/sscanf.xml
Thomas Schoefbeck e6758715ec typo
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@113060 c90b9560-bf6c-de11-be94-00142212c4b1
2003-01-22 21:37:33 +00:00

90 lines
2.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/strings.xml, last change in rev 1.33 -->
<refentry id="function.sscanf">
<refnamediv>
<refname>sscanf</refname>
<refpurpose>
Parses input from a string according to a format
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>mixed</type><methodname>sscanf</methodname>
<methodparam><type>string</type><parameter>str</parameter></methodparam>
<methodparam><type>string</type><parameter>format</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>var1</parameter></methodparam>
</methodsynopsis>
<para>
The function <function>sscanf</function> is the input analog of
<function>printf</function>. <function>sscanf</function> reads
from the string <parameter>str</parameter> and interprets it
according to the specified <parameter>format</parameter>. If only
two parameters were passed to this function, the values parsed
will be returned as an array.
</para>
<para>
Any whitespace in the format string matches any whitespace in the input
string. This means that even a tab \t in the format string can match a
single space character in the input string.
</para>
<para>
<example>
<title><function>sscanf</function> Example</title>
<programlisting role="php">
<![CDATA[
// getting the serial number
$serial = sscanf("SN/2350001","SN/%d");
// and the date of manufacturing
$mandate = "January 01 2000";
list($month, $day, $year) = sscanf($mandate,"%s %d %d");
echo "Item $serial was manufactured on: $year-".substr($month,0,3)."-$day\n";
]]>
</programlisting>
</example>
If optional parameters are passed, the function will return the
number of assigned values. The optional parameters must be passed
by reference.
<example>
<title><function>sscanf</function> - using optional parameters</title>
<programlisting role="php">
<![CDATA[
// get author info and generate DocBook entry
$auth = "24\tLewis Carroll";
$n = sscanf($auth,"%d\t%s %s", &$id, &$first, &$last);
echo "<author id='$id'>
<firstname>$first</firstname>
<surname>$last</surname>
</author>\n";
]]>
</programlisting>
</example>
</para>
<para>
See also <function>fscanf</function>, <function>printf</function>,
and <function>sprintf</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->