位置: 编程技术 - 正文

PHP字符串函数sscanf()的用法(在php中,字符串有哪些表示形式)

编辑:rootadmin
sscanf

推荐整理分享PHP字符串函数sscanf()的用法(在php中,字符串有哪些表示形式),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:php字符串赋值,php 字符串函数,php 字符串函数,php字符串定义,php字符串型数据的定义方式,在php中,字符串有哪些表示形式,php字符串定义的三种方式,php字符串定义,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4 >= 4.0.1, PHP 5)

sscanf — 根据指定格式解析输入的字符

说明 mixed sscanf ( string $str , string $format [, mixed &$... ] )

这个函数 sscanf() 输入类似 printf()。 sscanf() 读取字符串str 然后根据指定格式format解析, 格式的描述文档见 sprintf()。

指定的格式字符串中的任意空白匹配输入字符串的任意空白.也就是说即使是格式字符串中的一个制表符 t 也能匹配输入 字符串中的一个单一空格字符

参数

str

将要被解析的 字符串.

format

The interpreted format for 解析str的格式, 除了以下不同外,其余的见 sprintf()的描述文档: 函数不区分语言地区 F, g, G 和 b 不被支持. D 表示十进制数字. i stands for integer with base detection. n stands for number of characters processed so far.

... PHP字符串函数sscanf()的用法(在php中,字符串有哪些表示形式)

可以选参数将以引用方式传入,它们的值将被设置为解析匹配的值

返回值

如果仅传入了两个参数给这个函数,解析后将返回一个数组,否则,如果可选参数被传入,这个函数将返回被设置了值的个数

如果format存在的子字符串比 str内可用的多, -1 将被返回.

范例

Example #1 sscanf() 例子

<?php//gettingtheserialnumberlist($serial)=sscanf("SN/","SN/%d");//andthedateofmanufacturing$mandate="January";list($month,$day,$year)=sscanf($mandate,"%s%d%d");echo"Item$serialwasmanufacturedon:$year-".substr($month,0,3)."-$dayn";?>

If optional parameters are passed, the function will return the number of assigned values.

Example #2 sscanf() - using optional parameters

<?php//getauthorinfoandgenerateDocBookentry$auth="tLewisCarroll";$n=sscanf($auth,"%dt%s%s",$id,$first,$last);echo"<authorid='$id'><firstname>$first</firstname><surname>$last</surname></author>n";?>

参见

fscanf() - 从文件中格式化输入 printf() - 输出格式化字符串 sprintf() - Return a formatted string

PHP字符串函数soundex()的用法 soundex(PHP4,PHP5)soundexCalculatethesoundexkeyofastring说明stringsoundex(string$str)Calculatesthesoundexkeyofstr.Soundexkeyshavethepropertythatwordspronouncedsimilarlyproducethesamesoundexkey,andca

PHP字符串函数similar_text()的用法 similar_text(PHP4,PHP5)similar_text计算两个字符串的相似度说明intsimilar_text(string$first,string$second[,float&$percent])两个字符串的相似程度计算依据ProgrammingClassics:Impl

PHP字符串函数setlocale()的用法 setlocale(PHP4,PHP5)setlocaleSetlocaleinformation说明stringsetlocale(int$category,string$locale[,string$...])stringsetlocale(int$category,array$locale)Setslocaleinformation.参数categorycategoryisa

本文链接地址:https://www.jiuchutong.com/biancheng/278838.html 转载请保留说明!

上一篇:PHP字符串函数sha1()的用法(php字符串定义的三种方式)

下一篇:PHP字符串函数soundex()的用法(php字符串操作函数)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络