Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Placing HTML

Posted on 2002-04-08
4
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

604 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