php – 在某些索引后停止爆炸
如何在某个索引后停止爆炸功能.
例如 <?php $test="The novel Prognosis Negative by Art Vandelay expresses protest against many different things. The story covers a great deal of time and takes the reader through many different places and events,as the author uses several different techniques to really make the reader think. By using a certain type of narrative structure,Vandelay is able to grab the reader’s attention and make the piece much more effective and meaningful,showing how everything happened"; $result=explode(" ",$test); print_r($result); ?> 如果只想使用前10个元素怎么办($result [10]) 一种方法是先将字符串修剪到前10个空格(“”) 有没有其他方法,我不想将限制后的剩余元素存储在任何地方(使用正限制参数完成)?
那个函数的第三个参数是什么?
看看$limit参数. 手册:http://php.net/manual/en/function.explode.php 手册中的一个例子: <?php $str = 'one|two|three|four'; // positive limit print_r(explode('|',$str,2)); // negative limit (since PHP 5.1) print_r(explode('|',-1)); ?> 以上示例将输出:
在你的情况下: print_r(explode(" ",$test,10)); 根据php手册,当你使用limit参数时:
因此,您需要摆脱数组中的最后一个元素. $result = explode(" ",10); array_pop($result); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |