hello, and merry chistmas !

i need some help with the following problem:

let's say i have a variable:

$content = '<html><head><title>test page</title></head><body class="body"></body></html>';

and i want to echo that, to generate some html page...

echo $content;

ofcourse i know i can't do that... first of all because of the slashes (instead of class="body", i must write class=\"body\"), but that is not a true problem, because php adds slashes automatically when it sees quotes...
but it seems that i can't echo a variable containing html code... why ?
and if you have some suggestions, or maybe alternatives to this problem...

i really need this to work, so any answer will be greatly appreciated...
thank you in advance.

    Maybe because browsers render < ... > tags rather than print them out. If this is the case use a <pre> ... </pre> tag first or instead of angle brackets use &lt; and &gt;.

    hth

      that should work i know that " quotes cause problems inside the variable ' ' tags

        go like this

        $message = ?>
        
        
        add all ur html here
        
        
        <? ; 
        
        
        echo $message; 
        

          Nah; that will try echoing it out immediately, not put it in the variable.

          $message = <<<EOF
          <html>
          <head>
          <title></title>
          <body>
          <p style="font-family:sans-serif">
          This is all going into a variable named "\$message".
          </p>
          </body></html>
          EOF;
          
          echo $message;

          Note that you do need to escape $ signs unless you're embedding variables. To get around that you can go

          $message = '<html>
          <head>
          <title></title>
          <body>
          <p style="font-family:sans-serif">This is all going into a variable named "$message".
          </p>
          </body></html>';

          But then you can't embed variables (or most escape sequences). But that's okay:

          $foo='bar';
          $message = '<html>
          <head>
          <title></title>
          <body>
          <p style="font-family:sans-serif">This is all going into a variable named "$message"
          and also contains the string "'.$foo.'".
          </p>
          </body></html>';

            yea, but what if all the content from the $content variable is parsed from a form, like

            $content = $_POST['content'];
            

            i mean, that is the real problem...😕

              $content = '<html><head><title>test page</title></head><body class="body"></body></html>';

              just change this according:

              $content = "<html><head><title>test page</title></head><body class=body></body></html>";

              echo "$content";

              this will work and it will be html...

                Originally posted by Weedpacket
                Nah; that will try echoing it out immediately, not put it in the variable.

                opps sorry late post 😛

                  Originally posted by Dax
                  this will work and it will be html...

                  But deprecated for the past six years.

                  I don't see what the problem is any more.

                  $content = $_POST['content'];
                  
                  echo $content;
                  

                  If you're not doing anything like stripping out potentially malicious code, then that ought to work.

                    ok, thank you very much for all the help, guys, here it is the final (working) code:

                    //see if the get_magic_quotes() is off or not
                    if (!get_magic_quotes_gpc())
                    {
                    //if not, leave the variable content as it is: 
                    $content = $_POST['content'];
                    }
                    else
                    {
                    //else, get the slashes out from the variable content:
                    $content = stripslashes($_POST['content']);
                    }
                    echo $content;
                    
                      Write a Reply...