Jump to content


Photo

html code in string variables


  • Please log in to reply
3 replies to this topic

#1 roflpwnt

roflpwnt
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 05 May 2006 - 12:57 AM

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?

#2 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 05 May 2006 - 01:29 AM

[!--quoteo(post=371422:date=May 4 2006, 08:57 PM:name=roflwnt)--][div class=\'quotetop\']QUOTE(roflwnt @ May 4 2006, 08:57 PM) View Post[/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.

<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>

Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#3 mac.php

mac.php
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 05 May 2006 - 01:37 AM

[!--quoteo(post=371422:date=May 4 2006, 06:57 PM:name=roflwnt)--][div class=\'quotetop\']QUOTE(roflwnt @ May 4 2006, 06:57 PM) View Post[/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:

echo'Post:' . $var . ' ';  

notice the use of ' instead of "

I hope I'm understanding you right.

#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 05 May 2006 - 01:39 AM

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users