n8frog Posted September 14, 2010 Share Posted September 14, 2010 Hello again everyone. I have nearly completed my first php web site YAY! Unfortunately however I have run into a problem that I have no idea how to fix. I have created a simple click tracker to count the number of clicks on a certain link. This is working as intended but the problem is that I need to display the html code for the link so it can be copied and pasted into a web page. I have tried using < and > to display the tags however it does not seem to work. example [code=php:0]echo "<a href="http://www.mywebsite.com">Anchor Text</a>"; [/code] When I try to set the value of a text box with an echo similar to the one above, nothing is displayed in the text box at all. Also when I tried to use these escapes in regular html on my page, it displayed everything except the escaped characters. Am I missing something? My page has <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the head. Should my page be encoded in a different char set to make this work correctly? Quote Link to comment https://forums.phpfreaks.com/topic/213386-having-trouble-displaying-html-code-as-code/ Share on other sites More sharing options...
Pikachu2000 Posted September 14, 2010 Share Posted September 14, 2010 It should work using htmlentities(). <?php $var = 'This is a string with some <html><table><tr><td></td></tr></table></html> tags.'; echo htmlentities($var); ?> Quote Link to comment https://forums.phpfreaks.com/topic/213386-having-trouble-displaying-html-code-as-code/#findComment-1110974 Share on other sites More sharing options...
n8frog Posted September 14, 2010 Author Share Posted September 14, 2010 Wow using htmlentities() solved it thank you so much. I was ready to start banging my head against the wall lol. Quote Link to comment https://forums.phpfreaks.com/topic/213386-having-trouble-displaying-html-code-as-code/#findComment-1110991 Share on other sites More sharing options...
Pikachu2000 Posted September 14, 2010 Share Posted September 14, 2010 You're welcome. Please remember to mark the thread solved (if it indeed is) using the button in the lower left of the page . . . Quote Link to comment https://forums.phpfreaks.com/topic/213386-having-trouble-displaying-html-code-as-code/#findComment-1110992 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.