Hi,

I've looked around, but I can't find out how to put the content of a variable outside the PHP tags. For example I have tried:

<?php
$theVariable="?>
<p align="left">Here is the content of the variable, I can put quotation marks in without having to escape them</p>
<?php ";
echo "$theVariable";
?>

This returns the ?> as well as all the content.

Any help would be greatly appreciated.

Thanks.

    Ive found that having the "$example1 = <<<END" or "END;" on a line with whitespace before it will give errors or not work correctly.

    $example1 = <<<END 
      Any text here 
      $variables 
      "Qoutes" 
      \Slashs// 
    END; 
    
    $example2 = <<<ANY_THING_HERE 
       Anything 
    ANY_THING_HERE; 
    
    //You can also use it with print: 
    
    print <<<END; 
       Text: $text 
    END;
    

      Sorry, this doesn't seem to work with my code. I would also really like to keep the HTML code outside the <?php ?> tags to help me organise things with a template system.

      Thanks.

        You cannot assign a variable outside of PHP, the only way to really do it is to use my way(which should work, what error are you getting?). If you dont mind me saying, the PHP you posted in your original post looks bad compared to others things you can do.

          <?=$HTTP_SESSION_VARS["somevar"]?>

          Theres an example straight off PHP's website I have never tried this but remember seeing info about it on phps site if thats what your interested in. It allows you to use simple 1 line to list the vairable, I assume it echos it out maybe? try it and see 🙂

          Grant

            He wants to assign a variable outside of php, not echo it out.

            After doing some thinking you could probabally define your HTML into a text file and then put the HTML into the variable by doing:

            $var = file_get_contents("htmlFile.txt");
            echo $var; // Will output "Hello there!" in bold
            

            htmlFile.txt:

               <b>Hello there!</b>
            

              You always have to reference php variables in side of <? and ?>, so what your looking for is something like this:

              <?
              some php code
              $var = "hello";
              ?>

              some html code
              <?=$var?>

              <?= instructs php to automaticly echo whats inside the tag, and is the same as doing: <? echo $var; ?>

              There's no way around this. If you don't open up the tag, i.e. <? and close it, php will not know it's supposed to parse the code.

                Write a Reply...