Solved

Placing HTML

Posted on 2002-04-08
4
220 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.

828 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