php - 帮助处理 PHP 代码

标签 php

此代码存在语法错误。谁能告诉我问题出在哪里?提前致谢。

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>';

附注代码有点难读。尝试仅使用一种类型的引号来环绕字符串,然后可以在该字符串内安全地使用另一种类型的引号。

此外 - 请记住 - 如果您将字符串包裹在 ' 或 "- 您必须通过在其前面添加反斜杠来转义字符串中的此字符:\

http://php.net/manual/en/language.types.string.php

关于php - 帮助处理 PHP 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6839108/

相关文章:

php - DIV 向下一行

php - 使用 nginx 和 fastcgi 捕获 PHP 404 错误

php - 如何获得 PHP 中使用的实际 CPU 时间?

php - 在 easyphp 上使用 PHP 导入和导出 MySQL 数据库

php - 通过 Ajax、通过链接运行 PHP 脚本?

php - 如何将 Google Analytics 代码添加到 Drupal 7

php - Woocommerce 3 商店页面上“添加到购物车”下的“添加额外”按钮

php - wordpress menu-walker 中的 ACF 对象

PHP:在 1 行或多行上连接更好吗?或者有区别吗?

使用 C++ 的 PHP 扩展