___ROCK___ Posted August 30, 2009 Share Posted August 30, 2009 <?php $my_html = htmlspecialchars("<html> <head> <title> </title> </head><body>whats up </body></html>"); echo $my_html; ?> How can I format this code so it appears like this <html> <head> <title> </title> </head> <body>whats up </body> </html> Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/ Share on other sites More sharing options...
oni-kun Posted August 30, 2009 Share Posted August 30, 2009 You'll need to use regex or str_replace to create newlines after each tag.. such as.. replacing '<head>' with '<head><br/>\n'. Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909160 Share on other sites More sharing options...
.josh Posted August 30, 2009 Share Posted August 30, 2009 where is the string coming from? If you are hardcoding it like that, simply add \n after each tag (not <br/> : because you are using htmlspecialchars, it will just echo out the literal <br/>). Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909221 Share on other sites More sharing options...
___ROCK___ Posted August 30, 2009 Author Share Posted August 30, 2009 I tried both examples and nothing seem to work. Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909346 Share on other sites More sharing options...
___ROCK___ Posted August 30, 2009 Author Share Posted August 30, 2009 Can you guys show me a small example of what you mean on the above answers. Maybe I'm not doing it right. <?php $my_str = htmlspecialchars('<html> <head> </head </html>' ); echo $my_str; ?> how can I format that above code to look like this. <html> <title> </title> </html> Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909377 Share on other sites More sharing options...
.josh Posted August 30, 2009 Share Posted August 30, 2009 seriously? "simply add \n after each tag" <html>\n<head>\n</head>\n</html>\n etc... would you like me to hold your dick for you while you pee, too? Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909411 Share on other sites More sharing options...
___ROCK___ Posted August 31, 2009 Author Share Posted August 31, 2009 seriously? "simply add \n after each tag" <html>\n<head>\n</head>\n</html>\n etc... I did that but it did not work, and since you are a php guru show me something that works. would you like me to hold your dick for you while you pee, too? I don't you to hold my dick, Just open your mouth so I can pee and shit in it! Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909424 Share on other sites More sharing options...
___ROCK___ Posted August 31, 2009 Author Share Posted August 31, 2009 I don't you to hold my dick, Just open your mouth so I can pee and shit in it! I don't need you to hold my dick, Just open your mouth so I can pee and shit in it! Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909446 Share on other sites More sharing options...
.josh Posted August 31, 2009 Share Posted August 31, 2009 congrats. you managed to be even less mature than me. Not a task easily accomplished. Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-909453 Share on other sites More sharing options...
___ROCK___ Posted September 2, 2009 Author Share Posted September 2, 2009 Our childish behavior has set me off track for a bit. Now back to the main topic, I did not mention that I wanted see the formatted text. :'( Therefore what you have posted is correct, but i need to go one step further which is display the formatted code. So if i wanted to say "u r rite oh great one". i would like to have it displayed like this. <html> <title> The Grate One</title> <body> <p> You Are Right, Oh Great One! </p></body> </html> Thanks for all the php help, and for helping me relieve myself. Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-910633 Share on other sites More sharing options...
newbtophp Posted September 2, 2009 Share Posted September 2, 2009 Try str_replace: <?php $my_str = "<html>\n<title> The Grate One</title>\n<body>\n <p> u r Right, Oh Great One! </p>\n</body>\n</html>"; $my_str = str_replace('u', 'You', $my_str); $my_str = str_replace('r', 'Are', $my_str); highlight_string($my_str); ?> Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-910637 Share on other sites More sharing options...
___ROCK___ Posted September 2, 2009 Author Share Posted September 2, 2009 Mission accomplished! Great work newbtophp. Link to comment https://forums.phpfreaks.com/topic/172446-solved-formating-html-with-htmlspecialchars/#findComment-910643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.