此代码存在语法错误。谁能告诉我问题出在哪里?提前致谢。
echo "<div class='cvtitle'><div><a class="bloc_ca" href="'.$video['video_id'].'_'.str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20)).'.html"><b>".html_entity_decode(substr($video['video_title'],0,100))."..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>".html_entity_decode(substr($video['video_desc'],0,100))."</span></div><div class='cvviews'> View Count: <b>".$video['views']."</b></div></div></div>";
最佳答案
你必须逃避。而不是:
echo 'some text' . "aaaa"aaaa";
写:
echo 'some text' . "aaaa\"aaaa";
将您的示例重写为如下内容:
echo "<div class='cvtitle'><div><a class=\"bloc_ca\" href=\"" . $video['video_id']
. '_' . str_replace(" ","-",substr(html_entity_decode($video['video_title']),0,20))
. '.html"><b>'
. html_entity_decode(substr($video['video_title'],0,100))
. "..</b></a></div><div class='cvdisc'><span style='word-break:wrap'>"
. html_entity_decode(substr($video['video_desc'], 0, 100))
. '</span></div><div class="cvviews"> View Count: <b>'
. $video['views']
. '</b></div></div></div>';
附注代码有点难读。尝试仅使用一种类型的引号来环绕字符串,然后可以在该字符串内安全地使用另一种类型的引号。
此外 - 请记住 - 如果您将字符串包裹在 ' 或 "- 您必须通过在其前面添加反斜杠来转义字符串中的此字符:\
关于php - 帮助处理 PHP 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6839108/