简体   繁体   English

是否可以注释掉包含特殊“特殊”字符的PHP代码行?

[英]Is it possible to comment out a line of PHP code containing special “special” characters?

This is probably not constructive at all, and I'm asking more of curiosity than anything else, because I know how to overcome this issue by modifying the code. 这可能根本不是建设性的,并且我要问的是更多的好奇心, 因为我知道如何通过修改代码来克服此问题。

Anyway, having this PHP line: 无论如何,拥有以下PHP行:

strip_tags(preg_replace('#<br\s*/?>#i', "\n", $nameXML));

Is there any way to comment out this line ? 有什么办法可以注释掉这一 ( without any modifications to it! ) I have already tried using // , /**/ , and # and in every case PHP has thrown a syntax error. 没有任何修改! )我已经尝试使用///**/#并且在每种情况下PHP都引发语法错误。

EDIT #1: I assume a commented line will not produce ANY output - if it does than it's not really commented out, is it? 编辑#1:我认为带注释的行不会产生任何输出-如果它比未真正注释掉的输出,是吗?

EDIT #2: Please don't try too hard answering this question. 编辑2:请不要尝试回答这个问题。 It's not a real issue. 这不是一个真正的问题。

The reason why you are getting a strange output is because of the particular ?> in your regex. 之所以得到奇怪的输出,是因为正则表达式中的特殊?> In this case, PHP is interpreting that as the end of the script, because the rest of the code is commented out. 在这种情况下,PHP会将其解释为脚本的结尾,因为其余代码已被注释掉。 To answer your question directly, in this case, you cannot comment out that particular line of code without editing it. 要直接回答您的问题,在这种情况下,您不能不编辑而注释掉特定的代码行。 You would have to remove the ?> portion of the regex in order for the script to continue to run normally. 您必须删除正则表达式的?>部分,以使脚本继续正常运行。

Edit: 编辑:

Additionally, it would work if you encapsulated the comment in /* */ according to this post . 此外,如果您在封装的评论这可行 /* */根据这一职位 However , because the regex has */ it is prematurely ending the block style comment, thus still breaking out of PHP mode and returning to HTML mode. 但是 ,由于正则表达式具有*/所以它过早地结束了块样式注释,因此仍然脱离了PHP模式并返回到HTML模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM