简体   繁体   中英

Comments inside single quotes - PHP

How can I simply add a comment in php enclosed in single quotes:

// Output variable

$actions = '<a onclick="doLike('.$id.', '.$y.')" id="doLike'.$id.'">'.$state.'</a> - <a     onclick="focus_form('.$id.')">'.$LNG['comment'].'</a> - <a onclick="share('.$id.')">'.$LNG['share'].'</a> <div class="like_btn" id="like_btn'.$id.'"> '.$people.$likes.'</div>';

I am trying to comment out (hide) this bit of code...

- <a     onclick="focus_form('.$id.')">'.$LNG['comment'].'</a> -

But no luck with /* or //

There are no "string comments" in PHP. You need to restructure your code so that you don't have to put comments inside strings.

For instance, you could have one tag per line:

$actions = '<a onclick="doLike('.$id.', '.$y.')" id="doLike'.$id.'">'.$state.'</a>';
$actions .= ' - <a     onclick="focus_form('.$id.')">'.$LNG['comment'].'</a>';
$actions .= ' - <a onclick="share('.$id.')">'.$LNG['share'].'</a>';
$actions .= '<div class="like_btn" id="like_btn'.$id.'"> '.$people.$likes.'</div>';

With this structure, you can comment out the line you don't like.

You mean an HTML comment? Those look like

<!--a onClick..... -->

But note that each comment is a tag, so you have to comment even the visible text in its own tag as well

尝试这个

 $actions = '<a onclick="doLike('.$id.', '.$y.')" id="doLike'.$id.'">'.$state.'</a> <!-- - <a     onclick="focus_form('.$id.')">'.$LNG['comment'].'</a> --> - <a onclick="share('.$id.')">'.$LNG['share'].'</a> <div class="like_btn" id="like_btn'.$id.'"> '.$people.$likes.'</div>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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