roflpwnt Posted May 5, 2006 Share Posted May 5, 2006 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 Link to comment https://forums.phpfreaks.com/topic/9096-html-code-in-string-variables/ Share on other sites More sharing options...
phporcaffeine Posted May 5, 2006 Share Posted May 5, 2006 [!--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] Quote Link to comment https://forums.phpfreaks.com/topic/9096-html-code-in-string-variables/#findComment-33465 Share on other sites More sharing options...
mac.php Posted May 5, 2006 Share Posted May 5, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/9096-html-code-in-string-variables/#findComment-33468 Share on other sites More sharing options...
toplay Posted May 5, 2006 Share Posted May 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/9096-html-code-in-string-variables/#findComment-33469 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.