Solved

Placing HTML

Posted on 2002-04-08
4
205 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:kplonk
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 6926772
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
 
0
 
LVL 5

Accepted Solution

by:
andriv earned 20 total points
ID: 6926847
Why not store it in a variable:
(I recommend using 'here docs' so you do not have to escape quotes)

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

Now you can echo to display. And if you want to insure it's a string you can use:

$myHTML = stringval($myHTML);



0
 

Author Comment

by:kplonk
ID: 6928823
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??
0
 
LVL 5

Expert Comment

by:andriv
ID: 6928896
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now