1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to escape PHP code in html

Discussion in 'PHP' started by mrpixel, May 8, 2010.

  1. #1
    Hello,

    I have this code:
    $html = <<<HTML
        <p>Here is the PHP</p>
    <h2><?php echo="Hello" ?></h2>
    HTML;
    echo $html;
    ?>
    PHP:
    But the php line (<?php echo="Hello" ?>) is considerated html
    How i escape this "<?php echo="Hello" ?>" from HTML tags?
    SEMrush
    Thanks
    Regards
     
    mrpixel, May 8, 2010 IP
    SEMrush
  2. Stealth777

    Stealth777 Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    One thing I noticed was that
    <?php echo="Hello" ?>
    Code (markup):
    is supposed to be
    <?php echo 'Hello'; ?>
    Code (markup):
    Try changing that and see if it works. BTW make sure you are running on a host or localhost, otherwise just loading the file in your browser will result in the PHP not being parsed, which in return shows up in the HTML.
     
    Stealth777, May 8, 2010 IP
  3. mrpixel

    mrpixel Member

    Messages:
    433
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    Yes, i run it on the localhost, but the problem is that tha PHP line is considerated html <?php echo 'Hello'; ?> becouse is inside the HTML tags
     
    mrpixel, May 8, 2010 IP
  4. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,063
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    195
    #4
    What you are trying to does not exist in PHP

    If you wan't a variable to be parsed withing a HEREDOC syntax you can do the following:

    
    <?php
    
    $greeting = 'Hello';
    
    $html = <<<HTML
      <p>Here is the PHP</p>
      <h2>$greeting</h2>
    HTML;
    
    echo $html;
    
    ?>
    PHP:
     
    nabil_kadimi, May 8, 2010 IP
  5. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #5
    It sound like it's not being parsed as php within .html files. Edit /etc/httpd/httpd.conf. Amend this line to include .html:

    AddType application/x-httpd-php .php .php3 .phtml .html

    Then restart Apache.

    EDIT: Just re-read the post and miss read it the first time, ignore me, nabil_kadimi above has got it. :)
     
    mfscripts, May 8, 2010 IP
  6. live.co.uk

    live.co.uk Banned

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    just use html and when add php
    use the <?php ?>
     
    live.co.uk, May 8, 2010 IP
  7. mrpixel

    mrpixel Member

    Messages:
    433
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #7
    it doesn't work like this, the php code doesn't got effect
     
    mrpixel, May 8, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    <?php
    ob_start();
    ?>
        <p>Here is the PHP</p>
    <h2><?php echo "Hello"; ?></h2>
    <?php
    $html = ob_get_clean();
    ?>
    PHP:
     
    danx10, May 8, 2010 IP
  9. live.co.uk

    live.co.uk Banned

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ok i will give you big advice
    use any templete engine
     
    live.co.uk, May 8, 2010 IP
  10. Lam3r

    Lam3r Active Member

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #10
    that is extremely unhelpful and actually pretty idiotic advice live.co.uk, even more so because you mispelled template.

    I honestly don't even understand the logic behind what you're trying to do, if you want the webpage generated entirely with PHP, just echo each HTML element and escape all the characters, like so:
    
    <?php
    echo "<<<HTML";
    echo "<br />";
    echo "    <p>Here is the PHP</p>";
    echo "<h2>$variableinPHP</h2>"
    echo "HTML\;";
    ?>
    
    PHP:
     
    Lam3r, May 8, 2010 IP
  11. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #11
    uh.. his advice is better then yours.. putting html in an echo is horrible coding..
     
    killaklown, May 8, 2010 IP
  12. Lam3r

    Lam3r Active Member

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #12
    Agreed, but that's as close a way as i can understand from OP...
     
    Lam3r, May 8, 2010 IP
  13. mrpixel

    mrpixel Member

    Messages:
    433
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #13
    i need to do a strong footer encryption, and i decided to try this site www[dot]byterun[dot]com/free-php-encoder.php. But if i insert my html code as it is, the PHP tags are unobserved.

    Here is the code:
    
    <p> <span><?php bloginfo('name'); ?> <?php echo date('Y'); ?></span></p><?php include (TEMPLATEPATH . '/searchform.php'); ?><p>
    
    
    PHP:
    so if i paste this code into encoder the PHP is not observed
     
    mrpixel, May 9, 2010 IP
  14. Lam3r

    Lam3r Active Member

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #14
    Oh lol i think i know why
    PHP isn't installed on your computer is it? I had the same problem the other day then slapped myself for not realizing. Get WampServer or just use a free host to test your PHP code. ;P

    ~ Lam3r
     
    Lam3r, May 9, 2010 IP
  15. mrpixel

    mrpixel Member

    Messages:
    433
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #15
    man... it is installed XAMPP
     
    mrpixel, May 10, 2010 IP
  16. plaieu

    plaieu Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    study it ..........
     
    plaieu, May 10, 2010 IP