<?php $string = "This is an example string";
$arrstring=explode(" ",$string);
for ($i=0;$i<count($arrstring);$i++)
{
echo "world:".$arrstring[$i]."<br>\n";
}?>你的要求,用FOR实现的
$arrstring=explode(" ",$string);
for ($i=0;$i<count($arrstring);$i++)
{
echo "world:".$arrstring[$i]."<br>\n";
}?>你的要求,用FOR实现的
<?php
$string = "This is an example string";
$tok = strtok($string, " ");for(;$tok !== false;) {
echo "Word=$tok<br />";
$tok = strtok(" ");
}
?>
希望能拿你一百分,哈哈。<?php
$string = "This\tis an\nexample string"; for($tok = strtok($string, " \n\t");$tok !== false;$tok = strtok(" \n\t")) {
echo "Word=$tok<br />";
}
?>
echo "Word=$tok<br />";
$tok = strtok(" ");
}
?>
$string = "This\tis an\nexample string"; for($tok = strtok($string, " \n\t");$tok !== false;$tok = strtok(" \n\t")) {
echo "Word=$tok<br />";
}
?>
________________________
你把cn.php.net上的例子用for改了,但我想问,\n\t为什么加在那里?是怎么根据空格切割的?
感谢keaizhong(可爱钟)(温州的PHPER)(19801010),感谢大家的回答!
结贴!回者都有分!
$string = "This is an example string"; for ($tok = strtok ($string," ");$tok;$tok = strtok (" "))
{ echo "Word=$tok<br>"; }?>楼主就是在这 for ($tok = strtok ($string," ");$tok;$tok = strtok (" ")) 少一个空格符
keaizhong(可爱钟)(温州的PHPER)(19801010)
都那么多分了还