www.webdeveloper.com
Results 1 to 14 of 14

Thread: echoing or printing html with quotes

  1. #1
    Join Date
    Jul 2006
    Posts
    373

    echoing or printing html with quotes

    hi,

    as you know, when you use the echo or print function to output html code, its necessary to escape all the quotes with a \ before any quote so php codes doesnt get messed up. Howeveri have seen some cases where this is not necessary because after the print or echo strings there is a CUT <<< like thing that appears to allow you to include the html code as is, without modifying the quotes. Im not really sure about this so i wanted to ask you if you can tell me more specifically whats that CUT <<< for and if it really can help you deprecate the use of back slashes when you echo html with quotes within.

    Thank you.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,331
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2006
    Posts
    373
    So after the <<< you can put whatever word you can and not precisely CUT? so if i want to print some html code this should work

    echo <<<EOT

    <img src="img.jpg" width="30px" height="40px"> EOT;


    is that correct?

    thank you.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,331
    The closing "word" and terminating semi-colon must be on a line by itself with no leading white-space of any kind.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2006
    Posts
    373
    so like this?

    <img src="img.jpg" width="30px" height="40px">
    EOT;

  6. #6
    Join Date
    Jul 2006
    Posts
    373
    i just tested this line and it didnt work. I get an error.

    echo <<<EOT
    <img src="images/total.jpg" width="297" height="21">
    EOT;

    whats wrong with this line?

  7. #7
    Join Date
    Mar 2006
    Location
    Chennai
    Posts
    32
    Hi,
    $string= <<<EOT

    <img src="images/total.jpg" width="297" height="21">

    EOT;

    echo $string;


    It will definetely work. But ensure that semicolon will not occur after <<<EOT. It will give error.
    By
    John Diraviyam,
    PHP Developer.

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,331
    Works fine for me:
    PHP Code:
    <?php
    echo <<<EOT
    <img src="images/total.jpg" width="297" height="21">
    EOT;

    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Jul 2006
    Posts
    373
    Now it works both ways. Thank you 2!

  10. #10
    Join Date
    Jul 2006
    Posts
    373
    Sorry, i have another question. What if i want to include a variable within that echoed html? it should work right? its just that im not defining the variable right

    <?php
    $menu = include("menu.html");
    echo <<<EOT
    <img src="images/total.jpg" width="297" height="21">
    $menu
    EOT;
    ?>

    i want the variable to call the include function to insert that html bit, but it does it not in the echoed code, but where im supposed to be defining the variable. Could you tell me please how to define the variable as an include?

    thank you.

  11. #11
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,331
    Most likely the problem is that include() does not return anything, unless you happen to have a return() statement being executed within the main body of the included file.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  12. #12
    Join Date
    Jul 2006
    Posts
    373
    But for example, how do you do when you want a variable to return a template bit?

  13. #13
    Join Date
    Jul 2006
    Posts
    373
    i found it! this does the job $menu = file_get_contents('menu.html'); if you have any alternative for that just let me know

  14. #14
    Join Date
    Jul 2006
    Posts
    373
    hello? anybody there?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles