Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP string containing two forward slashes in

Tags:

string

php

This is probably a very simple question, but I just can't figure it out. I want to define a string containing two forward slashes

$htmlcode="text//text";

From what I understand what follows after // are comments.

Question: How do create a string containing //?

like image 686
Thomas Avatar asked Sep 18 '25 02:09

Thomas


2 Answers

Parsing of the language is a little bit tricky. Within a string literal, comments and other language features are not triggered (except for special characters which need to be escaped). Also, within block comments, line-comments are not valued.

$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 */
like image 147
smdrager Avatar answered Sep 19 '25 18:09

smdrager


$htmlcode="text//text"; //this is comment.

Your string is already defined as you want it to be. Check out docs: http://php.net/manual/en/language.basic-syntax.comments.php

You should use some IDE or syntax highlighter, you will understand code more clearly. Notepad++ is free and lightweight http://notepad-plus-plus.org/download

like image 26
Dejan Marjanović Avatar answered Sep 19 '25 17:09

Dejan Marjanović