Skip to:
Content
Pages
Categories
Search
Top
Bottom

Skipping code in .php files and CSS.


  • InvTrdr
    Member

    @invtrdr

    In CSS I use /*………*/ for a few lines of code or ……..// for just a line so that code is skipped or avoided. Will this work in a .php file also? I would like to skip code to test it out without deleting the original code. Just want to mask the original code so I can go back to it if I make a mistake.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

  • chrishajer
    Participant

    @chrishajer

    Yes, you can comment out a block of code in between the <?php and ?> by using /* commented this part */. For example,

    <?php
    echo $user;
    /* echo $phone; */
    ?>

    The phone would no longer be displayed because you commented it out. It won’t even appear in the source of the page when viewed in the browser, unlike a HTML comment <!-- commented this part --> or CSS comments (which are always visible.)


    chrishajer
    Participant

    @chrishajer

    For a single line of PHP, you can just do this:

    // echo $phone;

    And that single line will be commented out. If what you’re commenting spans more than one line, use the /* commented code */ method.


    InvTrdr
    Member

    @invtrdr

    Thanks. I will ahve to try it again as once when I used it in my footer.php I actually saw the /* and */ on the page itself. I might have inserted it the wrond way.

    Thanks.


    chrishajer
    Participant

    @chrishajer

    It definitely needs to be inside the <?php ?> code block, or it’s just HTML to the browser. You probably didn’t have it in a code block if you saw it displayed.

    A syntax highlighting editor helps a lot with this. It helps you see what is code and what is plain text.


    InvTrdr
    Member

    @invtrdr

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar