saving content in a variable (cfsavecontent)
Moderator: General Moderators
-
returnButton
- Forum Newbie
- Posts: 6
- Joined: Sat Jul 05, 2003 5:06 pm
saving content in a variable (cfsavecontent)
ok, this might be simple; i need to save a big block of HTML in a variable, thus:
instead of doing:
$string="";
$string.="some html";
$string.="some html";
$string.="some html";
echo $string;
something like:
$string=
{
lots of HTML
lots of HTML
lots of HTML
}
echo $string;
i need this so i can do other things with the $string before i output it, and i'd rather stick the HTML down on the page than have to build it up in a string manually.
in coldfusion there's a tag called cfsavecontent, which is my friend. is there anything similar in PHP?
thanx..
instead of doing:
$string="";
$string.="some html";
$string.="some html";
$string.="some html";
echo $string;
something like:
$string=
{
lots of HTML
lots of HTML
lots of HTML
}
echo $string;
i need this so i can do other things with the $string before i output it, and i'd rather stick the HTML down on the page than have to build it up in a string manually.
in coldfusion there's a tag called cfsavecontent, which is my friend. is there anything similar in PHP?
thanx..
http://php.net/manual/en/language.types ... ax.heredoc
[php_man]ob_[/php_man]* functions.
[php_man]ob_[/php_man]* functions.
just giving an example...Weirdan wrote:http://php.net/manual/en/language.types ... ax.heredoc
[php_man]ob_[/php_man]* functions.
Code: Select all
$string= <<<foo
lots of HTML
lots of HTML
lots of HTML
foo;
//......somewhere down the road...over the rainbow...whatever
echo $string;- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
so your gonna just call the string in a echo like this?
as long as you dont have to use the contents of the string anywhere else you could just do this
and if you have to use the $string somewhere else what infolock said is perfectly fine too.
but in my opinion less code == better
Code: Select all
<?php
$string = "loads of html";
if (blah == blah)
{
echo $string;
}
else
{
echo "die die die";
}
?>Code: Select all
<?php
if (blah == blah)
{
Print <<< EOT
loads of html goes here
EOT;
}
else
{
echo "die die die";
}
?>but in my opinion less code == better
-
returnButton
- Forum Newbie
- Posts: 6
- Joined: Sat Jul 05, 2003 5:06 pm
Nay seems to like it alot
But I'm not really too into it. I usually just echo it in a variable or just exit out of the PHP and code it straight into the HTML.
Example:
But I'm not really too into it. I usually just echo it in a variable or just exit out of the PHP and code it straight into the HTML.
Example:
Code: Select all
<?php
$variable = " blah ";
$variable = trim($variable);
?>
<table>
<tr><td>
<?php
echo $variable;
?>
</td></tr>
</table>- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
I myself love Heredoc and use it ALWAYS, and duff yes you can exit out of the php command, but as far as i'm concerned thats pointless if your gonna go right back into it, i also find that Heredoc instead of echo or print can make a script a bit easier to comprehend......best of luck with heredoc, and i hope you can figure out everything you wish to acomplish