PHP中Strtok的疑惑 [英] Doubt regarding Strtok in PHP
本文介绍了PHP中Strtok的疑惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?php
$string = "sandesh commented on institue international institute of technology";
/* Use tab and newline as tokenizing characters as well */
$tok = strtok($string, " \n\t");
echo $tok
?>
上面的代码给了我输出 sandesh.
The above code gives me output sandesh.
但是如果我想要输出commented onstitute International Institute of Technology",那么我应该如何修改上面的代码.
But if I want the output "commented on institute international institute of technology", then how should I modify the above code.
感谢和问候桑德斯
推荐答案
<?php
$string = "sandesh commented on institue international institute of technology";
echo substr($string,strpos($string," ")+1);
文档
编辑
我实际上需要第四个标记之后的字符串
i actually need the string after the fourth token
<?php
$string = "sandesh commented on institue international institute of technology";
$str_array = explode(" ",$string);
$str_array = slice($str_array,4);
echo implode(" ",$str_array);
- http://php.net/manual/en/function.explode.php
- http://www.php.net/manual/en/function.内爆.php
- http://php.net/manual/en/function.array-slice.php
这篇关于PHP中Strtok的疑惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文