首页 > Web开发 > 详细

php strtok()函数用法,及使用时遇到的问题

时间:2015-09-26 20:00:37      阅读:348      评论:0      收藏:0      [点我收藏+]

strtok()函数:用来将一段字符串分割为子字符串

strtok(string $str, string $token)

strtok( string $token) 

//仅第一次调用$str,以后只使用$token,因为此函数会记住字符串,新字符串,只要在输入即可。。。

//注意点:。。。。。。。。。。。。。。。

//如果使用单引号包含带有转移字符的字符串,那么转义字符将失去意义。。


//如果用单引号包含的话,那么是以\,n,t来分割字符串的

//单引号:包含字符串,那么\n\t就没有了意义,只是变成了字符
//$str = ‘This is\tan example\nstring‘;
//得使用""才可以
$str = ‘This is\tan example\nstring‘;

//$token = strtok($str, ‘ \n\t‘);
//while ($token) {
//    echo "word = $token <br />";
//    $token = strtok(‘ \n\t‘);
//}
//输出
/**
 * word = This
 * word = is
 * word = a
 * word = example
 * word = s
 * word = ri
 * word = g
 */

//所以要注意

//双引号包含
//分割空格,\n,\t
$token = strtok($str," \n\t");
while ($token) {
    echo "word = $token <br />";
    $token = strtok(" \n\t");
}
//$string  =  "This is\tan example\nstring" ;
///* 使用制表符和换行符作为分界符 */
//word = This 
//word = is 
//word = an 
//word = example 
//word = string

 

php strtok()函数用法,及使用时遇到的问题

原文:http://www.cnblogs.com/tumio/p/4841157.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!