PHP string containing two forward slashes in

16,776

Solution 1

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

Solution 2

$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

Solution 3

Your code is fine.

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

Share:
16,776
Thomas
Author by

Thomas

Updated on June 28, 2022

Comments

  • Thomas
    Thomas almost 2 years

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