$var = "a b // I want to comment here but it becomes a string instead c" I want to insert a comment in the middle of multiple line string in PHP, but I can't. I've tried /**/, //, and #.
Does anyone know how to do it?
$var = "a b ".// I want to comment here but it becomes a string instead." "c"; echo $var; ".// as the "string commenting operator".Only possible with concatenation and a comment:
$var = "a\n" . // "b\n" . "c"; you can also write your code like this. If you want multi line you can use \n at after string.
$string = 'First'; $string .= 'Comment section ';//this where you can comment $string .= 'Last'; .= is possible.<?php $var = "a\n" . "b\n" . //this where you can comment "c"; echo $var; ?> Output
a b c Check code and output in editor. Click Here
You got your answer but I thought I'll share my 2 cents as well: You could use the HTML comment tag:
<!--This is a comment. Comments are not displayed in the browser--> The catch is that users can view this comment if they view source!
With the example you gave:
$var = "a b <!--I want to comment here but it becomes a string instead--> c"; And while we're at it, you can use /**/ inside Style tag(CSS):
.Class { width: 100%; /*The width*/ } Or as someone already suggested just close the string and comment inside PHP:
$var = "a". "b". //Comment "c"; And if you want to maintain the new line:
$var = "a\n"
xmodifier to allow it and generous whitespace)