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
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]
Link to comment
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.
Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.