我想知道这段代码中的语法错误是什么。
echo "<p id='hide_text_$heading->id' >"preg_replace($rx, "<b>$0</b>", $heading->shortHeadline)"</p>";
使用.
连接字符串。将代码更改为
echo "<p id='hide_text_$heading->id' >" . preg_replace($rx, "<b>$0</b>", $heading->shortHeadline) . "</p>";
连接三个部分或将每个语句分开:
echo "<p id='hide_text_$heading->id' >";
echo preg_replace($rx, "<b>$0</b>", $heading->shortHeadline);
echo "</p>";
关于字符串操作符的更多信息
你忘记连接了吗?.
如果你指的是变量名,$0也有语法错误。
-
变量名不能以数字开头
-
我记得只有_和字符串字符。
echo "<p id='hide_text_".$heading->id."' >" . preg_replace($rx, "<b>.$0.</b>", $heading->shortHeadline) . "</p>";
你可以阅读更多关于concatation