Takamine334 Posted June 19, 2008 Share Posted June 19, 2008 Hi - I'm brand new to PHP. I'm trying to figure out how to echo some HTML. The problem is, I need it to echo as though it were text, not actual HTML to be used. For example, how would I echo </title><body> so that when I viewed the PHP page online, it would show: </title><body> Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/ Share on other sites More sharing options...
trq Posted June 19, 2008 Share Posted June 19, 2008 <?php echo htmlentities('</title><body>'); ?> Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-568681 Share on other sites More sharing options...
Takamine334 Posted June 20, 2008 Author Share Posted June 20, 2008 Thank you for your help! Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-570631 Share on other sites More sharing options...
Takamine334 Posted June 21, 2008 Author Share Posted June 21, 2008 quick question. How would I do a newline for each htmlentities? I keep getting errors when I put in \n Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571225 Share on other sites More sharing options...
trampolinejoe Posted June 22, 2008 Share Posted June 22, 2008 Depends what you mean? I think you should just be able to echo a <br> and that'll make a new line. show us some code Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571235 Share on other sites More sharing options...
atl_andy Posted June 22, 2008 Share Posted June 22, 2008 check into <pre> tags. they should do what you need. Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571277 Share on other sites More sharing options...
Stooney Posted June 22, 2008 Share Posted June 22, 2008 atl_andy was trying to say look into <pre></pre> tags. Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571292 Share on other sites More sharing options...
chuckman Posted June 22, 2008 Share Posted June 22, 2008 when I write html code into my php code I don't use htmlentities.. you can do this echo("</title> \n <body>"); Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571311 Share on other sites More sharing options...
HoTDaWg Posted June 22, 2008 Share Posted June 22, 2008 refer to the PHP manual. Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571316 Share on other sites More sharing options...
GingerRobot Posted June 22, 2008 Share Posted June 22, 2008 Quote quick question. How would I do a newline for each htmlentities? I keep getting errors when I put in \n A \n would be a newline character (on certain OS's). However, a browser does not display the newline character; you'll need the <br /> tag for that. Obviously this does not want to be converted with htmlentities(). Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571413 Share on other sites More sharing options...
Rezert Posted June 22, 2008 Share Posted June 22, 2008 <?php echo "<pre>"; echo htmlentities("</title> <body>"); echo "</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-571555 Share on other sites More sharing options...
atl_andy Posted June 26, 2008 Share Posted June 26, 2008 Oops...didn't post that correctly. Thanks chris. Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-574643 Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 The problem with telling him to just use htmlentities is that he probably doesn't know why it works. Takamine, html tags display as they are supposed to when "<anything>" is types. Anytime html sees a "<" it won't print anything out until after a closing ">" is printed, and then it makes whatever changes are needed til is sees a closing "</whatever>" tag. So for you to print a < without it thinking it's an html tag, you'll need to type out the assosicated 'entity' code for it. For example, ya know how if you type 5 space between words, it doesnt care and only adds one space? Well, the space entity code is ' ' so if you want 5 spaces, you need to type 5 's or else it won't print them. Now, the easy way to add entities is as suggested, with the htmlentities function. But if you dont' want to have to to that all the time, you can do the entity code for the < and > which is < and >, respectively. An easy way to remember is all entities starts with a & and end with a ;. And with these 2, you have a 'greater than' sign and a 'less than' sign. Hence, < and > There is an entity for (I think ) every character that needs to be displayed literally on the page. Hope that made sense. Hope that made sense. Link to comment https://forums.phpfreaks.com/topic/110842-how-can-i-echo-html/#findComment-574661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.