Itako
Itako

Reputation: 2069

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:

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.

EDIT #1: I assume a commented line will not produce ANY output - if it does than it's not really commented out, is it?

EDIT #2: Please don't try too hard answering this question. It's not a real issue.

Upvotes: 2

Views: 180

Answers (1)

Lance
Lance

Reputation: 1897

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. 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.

Upvotes: 1

Related Questions