(PHP 4 >= 4.0.1, PHP 5, PHP 7)
sscanf — 锟斤拷锟斤拷指锟斤拷锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟�
锟斤拷锟斤拷锟斤拷锟� sscanf() 锟斤拷锟斤拷锟斤拷锟斤拷
printf()锟斤拷 sscanf()
锟斤拷取锟街凤拷锟斤拷str
然锟斤拷锟斤拷锟街革拷锟斤拷锟绞�format
锟斤拷锟斤拷, 锟斤拷式锟斤拷锟斤拷锟斤拷锟侥碉拷锟斤拷 sprintf()锟斤拷
指锟斤拷锟侥革拷式锟街凤拷锟斤拷锟叫碉拷锟斤拷锟斤拷瞻锟狡ワ拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷锟斤拷锟秸帮拷.也锟斤拷锟斤拷说锟斤拷使锟角革拷式锟街凤拷锟斤拷锟叫碉拷一锟斤拷锟狡憋拷锟� \t 也锟斤拷匹锟斤拷锟斤拷锟斤拷 锟街凤拷锟斤拷锟叫碉拷一锟斤拷锟斤拷一锟秸革拷锟街凤拷
str
锟斤拷要锟斤拷锟斤拷锟斤拷锟斤拷 锟街凤拷锟斤拷.
format
The interpreted format for 锟斤拷锟斤拷str
锟侥革拷式, 锟斤拷锟斤拷锟斤拷锟铰诧拷同锟解,锟斤拷锟斤拷募锟�
sprintf()锟斤拷锟斤拷锟斤拷锟侥碉拷:
...
锟斤拷锟斤拷选锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫凤拷式锟斤拷锟诫,锟斤拷锟角碉拷值锟斤拷锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷匹锟斤拷锟街�
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟襟将凤拷锟斤拷一锟斤拷锟斤拷锟介,锟斤拷锟斤拷锟斤拷锟斤拷锟窖★拷锟斤拷锟斤拷锟斤拷锟斤拷耄拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟截憋拷锟斤拷锟斤拷锟斤拷值锟侥革拷锟斤拷
锟斤拷锟�format
锟斤拷锟节碉拷锟斤拷锟街凤拷锟斤拷锟斤拷
str
锟节匡拷锟矫的讹拷,
-1 锟斤拷锟斤拷锟斤拷锟斤拷.
Example #1 sscanf() 锟斤拷锟斤拷
<?php
// getting the serial number
list($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";
?>
If optional parameters are passed, the function will return the number of assigned values.
Example #2 sscanf() - using optional parameters
<?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";
?>