By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

can you use html as value for php variable

P: n/a
Is there a way to use html as a value for a php variable while going
in and out of the php tag?

For example, can you do something like this?

<?php $strHtml = ?>
<p>somehtml here</p>
<?php ; ?>

so that the value of $strHtml equals "<p>somehtml here</p>"

Apr 26 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"KidBrax" <br***********@gmail.comwrote in message
news:11**********************@u32g2000prd.googlegr oups.com...
Is there a way to use html as a value for a php variable while going
in and out of the php tag?

For example, can you do something like this?

<?php $strHtml = ?>
<p>somehtml here</p>
<?php ; ?>

so that the value of $strHtml equals "<p>somehtml here</p>"
<?php
$strHtml = "<p>somehtml here<p>";
?>
Don't forget to end the line with a semicolon.
HTH
Vince
Apr 26 '07 #2

P: n/a
Rik
KidBrax wrote:
Is there a way to use html as a value for a php variable while going
in and out of the php tag?

For example, can you do something like this?

<?php $strHtml = ?>
<p>somehtml here</p>
<?php ; ?>

so that the value of $strHtml equals "<p>somehtml here</p>"
AFAIK, no. Which a simple test would show.
Heredoc saves a lot of escaping quotes though, if that's your problem:
$strHTML = <<<HTML
<p>someHtml here, where we dont have to worry about escaping ' and ", so
that'll just go fine. Hell, we can even use variables:
{$_SERVER['HTTP_HOST']}. The only thing that should be escaped here is
are valid variable names, so $names should be \$names.
HTML;
--
Rik Wasmus

Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Apr 26 '07 #3

P: n/a
"Vince Morgan" <vi****@REMOVEoptusnet.com.auwrote in message
news:46***********************@news.optusnet.com.a u...
>
"KidBrax" <br***********@gmail.comwrote in message
news:11**********************@u32g2000prd.googlegr oups.com...
Is there a way to use html as a value for a php variable while going
in and out of the php tag?

For example, can you do something like this?

<?php $strHtml = ?>
<p>somehtml here</p>
<?php ; ?>

so that the value of $strHtml equals "<p>somehtml here</p>"

<?php
$strHtml = "<p>somehtml here<p>";
?>
Don't forget to end the line with a semicolon.
Or close your tags </plike I just did ;)
HTH
Vince


Apr 26 '07 #4

P: n/a
KidBrax kirjoitti:
Is there a way to use html as a value for a php variable while going
in and out of the php tag?

For example, can you do something like this?

<?php $strHtml = ?>
<p>somehtml here</p>
<?php ; ?>

so that the value of $strHtml equals "<p>somehtml here</p>"
<?php ob_start(); ?>
<p>some html here</p>
<?php $strHtml = ob_get_clean(); ?>

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
Apr 26 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.