包含两个正斜杠的PHP字符串

时间:2011-04-06 02:26:52

标签: php string

这可能是一个非常简单的问题,但我无法弄清楚。我想定义一个包含两个正斜杠的字符串

$htmlcode="text//text";

根据我的理解//后面是评论。

问题:如何创建包含//?

的字符串

3 个答案:

答案 0 :(得分:7)

解析语言有点棘手。在字符串文字中,不会触发注释和其他语言功能(除了需要转义的特殊字符)。此外,在块注释中,行注释不受重视。

$example1 = 'hello /* this is not a comment */ '; /* but this is */
$example2 = 'hello // this is not a comment '; //but this is
$example3 = "works the same with double quotes /* not a comment */ //not a comment ";

/* comment example
   $thisIsAComment
   //this does not escape the closing */

答案 1 :(得分:5)

$htmlcode="text//text"; //this is comment.

您的字符串已按您希望的那样定义。 查看文档:{​​{3}}

您应该使用一些IDE或语法高亮显示器,您将更清楚地理解代码。 Notepad ++是免费且轻量级的http://php.net/manual/en/language.basic-syntax.comments.php

答案 2 :(得分:1)

你的代码很好。

我强烈建议您阅读Basic Syntax - Comments指南,以便更好地理解。

相关问题