<HTML ><HEAD ><TITLE >sscanf</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="String functions" HREF="ref.strings.html"><LINK REL="PREVIOUS" TITLE="sprintf" HREF="function.sprintf.html"><LINK REL="NEXT" TITLE="str_pad" HREF="function.str-pad.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.sprintf.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.str-pad.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.sscanf" ></A >sscanf</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN90754" ></A ><P > (PHP 4 >= 4.0.1)</P >sscanf -- Parses input from a string according to a format </DIV ><DIV CLASS="refsect1" ><A NAME="AEN90757" ></A ><H2 >Description</H2 >mixed <B CLASS="methodname" >sscanf</B > ( string str, string format [, string var1])<BR ></BR ><P > The function <B CLASS="function" >sscanf()</B > is the input analog of <A HREF="function.printf.html" ><B CLASS="function" >printf()</B ></A >. <B CLASS="function" >sscanf()</B > reads from the string <TT CLASS="parameter" ><I >str</I ></TT > and interprets it according to the specified <TT CLASS="parameter" ><I >format</I ></TT >. If only two parameters were passed to this function, the values parsed will be returned as an array. </P ><P > 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. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN90779" ></A ><P ><B >Example 1. <B CLASS="function" >sscanf()</B > Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >// 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";</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > If optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN90783" ></A ><P ><B >Example 2. <B CLASS="function" >sscanf()</B > - using optional parameters</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >// 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";</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.fscanf.html" ><B CLASS="function" >fscanf()</B ></A >, <A HREF="function.printf.html" ><B CLASS="function" >printf()</B ></A >, and <A HREF="function.sprintf.html" ><B CLASS="function" >sprintf()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.sprintf.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.str-pad.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >sprintf</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >str_pad</TD ></TR ></TABLE ></DIV ></BODY ></HTML >