我有以下文件,保存为.php:
<head>
<title>String Manipulation</title>
<meta charset = "utf-8">
</head>
<body>
<?php
$words = "Hello how are you";
$token = strtok($feedback, ' ');
echo $token.'<br />';
while ($token!='')
{
$token = strtok(' ');
echo $token.'<br />';
};
?>
</body>
</html>
我正在阅读一本关于php的书,他们有这个例子并声称它应该在一个新行上打印每个标记&#39;(在这种情况下我认为这将是每个单词?),但是当我运行此代码没有任何反应。我做错了什么? PS:如果重要的话,我正在和MAMP一起运行
答案 0 :(得分:0)
此代码应为:
<head>
<title>String Manipulation</title>
<meta charset = "utf-8">
</head>
<body>
<?php
$words = "Hello how are you";
$token = strtok($words, ' ');
echo $token.'<br />';
while ($token!='')
{
$token = strtok(' ');
echo $token.'<br />';
};
?>
</body>
</html>
答案 1 :(得分:0)
<?php
$words = "Hello how are you";
// Change $feedback to $words
$token = strtok($words, ' ');
echo $token.'<br />';
while ($token!=''){
$token = strtok(' ');
echo $token.'<br />';
}
?>