Jump to content

html code in string variables


roflpwnt

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?
Link to comment
https://forums.phpfreaks.com/topic/9096-html-code-in-string-variables/
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]
[!--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.

Archived

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

×
×
  • Create New...

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.