Php String Containing Two Forward Slashes In

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 //?

3 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 */
$htmlcode="text//text"; //this is comment.

Your string is already defined as you want it to be. Check out docs:

You should use some IDE or syntax highlighter, you will understand code more clearly. Notepad++ is free and lightweight

1

Your code is fine.

I would highly suggest reading the Basic Syntax - Comments guide to get a better understanding.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest