2011-04-06 71 views
1

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

$htmlcode="text//text"; 

从我理解的内容// //后面是什么意见。

问题:如何创建一个包含//的字符串?

回答

6

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

$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

您的代码很好。

我强烈建议阅读Basic Syntax - Comments指南以获得更好的理解。

+0

我的PHP代码包含:$ htmlcode1 =“<?xml version = \”1.0 \“encoding = \”UTF-8 \“?> \ n <!DOCTYPE html PUBLIC” - // W3C“;当我尝试回应字符串,我得到0.这是否有道理? – Thomas 2011-04-06 02:36:02

+0

对不起,迈克,我看到我的错误,没有把最后一个backslah infront“谢谢 – Thomas 2011-04-06 02:41:42

+0

没问题,托马斯。祝你好运! – 2011-04-06 02:43:05

相关问题