Link to home
Start Free TrialLog in
Avatar of kplonk
kplonk

asked on

Placing HTML

What i have is a block of html in a function called log

what i want to be able to do is return this block of html as a single string, who is this done.

function log()
{
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td width="100%" height = "10"><!--Spacor to top of table-->
      </td>
    </tr>
    <tr>
<?
}

this is what the function does at the mo i just echo the function but i now need to be able to return the whole html code as a single string.  This is not the full list the real function has arround 100 lines of html code.

thanks kieran
Avatar of Batalf
Batalf
Flag of United States of America image

Maybe you could try this:
function log()
{
ob_end_flush(); // Maybe you don't need this line
ob_start(); // Start buffering output
?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
   <tr>
     <td width="100%" height = "10"><!--Spacor to top of table-->
     </td>
   </tr>
   <tr>
<?
$myString = ob_get_contents(); // Put buffer into a string
ob_end_clean(); // Clearing buffer
return $myString;
}

What I have done is to start buffering the output, and at the end put the buffer into a string using ob_get_content();

Hopefully, this could help you out.

Batalf
 
ASKER CERTIFIED SOLUTION
Avatar of andriv
andriv

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kplonk
kplonk

ASKER

Thanks so much, works a treat just one small question the EndHere is a line name right?? does this have to be left most ie no chars proceding the line name??
No EndHere indicates the end of the string. The way the 'Here Docs' works is you variable = followed by three < followed by a flag (it can be anything you want)

$variable =<<<StopHere

What this means vaiable = everything until you see the end flag 'StopHere'.  Then when you finish with the string you indicate it with 'StopHere;' on the last line.

$varaible =<<<Finished
Put
your
data
here
Finish;

The beauty of the 'here docs' is you don't have to escape quotes and when you print it, it will send it as you typed it. You don't have to use \n to start new lines.

I am glad I was able to help.