Jump to content

Archived

This topic is now archived and is closed to further replies.

roflpwnt

html code in string variables

Recommended Posts

Hi, ive been looking all over the place for an answer to this question and have been unable to find an answer. When i try to echo a string variable that has and html code in it, that code is not read by the browser and just ends up as regular text. Just for reference, what im trying to do is take partuicular posts on my forum database and display them in another page. the post shows up, but if there are any liks, images, etc in the post, rather than the browser displaying the link or image it gives me the html. any suggestions?

Share this post


Link to post
Share on other sites
[!--quoteo(post=371422:date=May 4 2006, 08:57 PM:name=roflwnt)--][div class=\'quotetop\']QUOTE(roflwnt @ May 4 2006, 08:57 PM) [snapback]371422[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi, ive been looking all over the place for an answer to this question and have been unable to find an answer. When i try to echo a string variable that has and html code in it, that code is not read by the browser and just ends up as regular text. Just for reference, what im trying to do is take partuicular posts on my forum database and display them in another page. the post shows up, but if there are any liks, images, etc in the post, rather than the browser displaying the link or image it gives me the html. any suggestions?
[/quote]


Correct Way: echo "<span style=\"color: red;\">Test</span>";

Also, if you are echoing in the midst of regular HTML you'll need the " <?php " st the begining and " ?> " at the end, all assuming your server can parse php.

[code]
<html>

<head>

<title>

My Test

</title>

<body>

<p>

<ul type="circle">

<li> <?php echo "<span style=\"color: red;\">Test</span>"; ?> </li>

</ul>

</p>

</body>

</html>
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=371422:date=May 4 2006, 06:57 PM:name=roflwnt)--][div class=\'quotetop\']QUOTE(roflwnt @ May 4 2006, 06:57 PM) [snapback]371422[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi, ive been looking all over the place for an answer to this question and have been unable to find an answer. When i try to echo a string variable that has and html code in it, that code is not read by the browser and just ends up as regular text. Just for reference, what im trying to do is take partuicular posts on my forum database and display them in another page. the post shows up, but if there are any liks, images, etc in the post, rather than the browser displaying the link or image it gives me the html. any suggestions?
[/quote]
Because you are pulling this info out of a database, it will be hard to \" everything. So instead do echo($var);
or:

[code]
echo'Post:' . $var . ' ';  
[/code]

notice the use of ' instead of "

I hope I'm understanding you right.

Share this post


Link to post
Share on other sites
phpORcaffine is correct and I just want to add that if you're using htmlentities() function to echo the HTML string out, then that would be another reason why the HTML is displayed as text instead of the browser interpreting it.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.