webguync Posted August 8, 2008 Share Posted August 8, 2008 How can HTML code be removed with PHP in an example such as below? $string = "<span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span>"; Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/ Share on other sites More sharing options...
papaface Posted August 8, 2008 Share Posted August 8, 2008 <?php $string = '<span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span>'; echo strip_tags($string); ?> Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612003 Share on other sites More sharing options...
waynew Posted August 8, 2008 Share Posted August 8, 2008 Or $string = htmlentities("<span style=\"font-size:10px; font-weight:bold;\">Hello <em>World</em></span>"); echo $string; Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612033 Share on other sites More sharing options...
Jahren Posted August 8, 2008 Share Posted August 8, 2008 What those guys mean is that you have to think the opposite way. Don't search to remove lines, you have to tell the code to NOT show it Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612035 Share on other sites More sharing options...
papaface Posted August 8, 2008 Share Posted August 8, 2008 Or $string = htmlentities("<span style=\"font-size:10px; font-weight:bold;\">Hello <em>World</em></span>"); echo $string; That will produce:<span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span> which is not what the OP wants. Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612051 Share on other sites More sharing options...
waynew Posted August 8, 2008 Share Posted August 8, 2008 No. That will produce: <span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span> Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612053 Share on other sites More sharing options...
papaface Posted August 8, 2008 Share Posted August 8, 2008 No. That will produce: <span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span> Exactly, its not actually stripping the html tags at all. Its just replacing them with the entities. Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612055 Share on other sites More sharing options...
waynew Posted August 8, 2008 Share Posted August 8, 2008 He never said anything about stripping tags. He said "remove html". Which is what htmlentities( ) will do. <span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span> is not html. Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612057 Share on other sites More sharing options...
papaface Posted August 8, 2008 Share Posted August 8, 2008 He never said anything about stripping tags. He said "remove html". Which is what htmlentities( ) will do. <span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span> is not html. I think you'll find it is HTML but in its raw form. I think everyone else will agree with me that you're not actually removing anything at all. The OP should clarify. Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612059 Share on other sites More sharing options...
waynew Posted August 8, 2008 Share Posted August 8, 2008 I think you'll find it is HTML but in its raw form. I think everyone else will agree with me that you're not actually removing anything at all. The OP should clarify. It's not HTML? How is it HTML in it's raw form? It's been turned into something that will be printed on screen instead of interpreted as HTML? Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612064 Share on other sites More sharing options...
waynew Posted August 8, 2008 Share Posted August 8, 2008 This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities. PHP.net on htmlentities Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612066 Share on other sites More sharing options...
papaface Posted August 8, 2008 Share Posted August 8, 2008 I think the point of the OPs post is to not allow people to post HTML tags to his/her script. I think we're deviating from the subject a bit. The facts of the matter are that the OP did not ask for the HTML to be shown in entity form,. but he DID ask for the HTML to be removed, which I think I have provided the code for. Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612067 Share on other sites More sharing options...
waynew Posted August 8, 2008 Share Posted August 8, 2008 I think the point of the OPs post is to not allow people to post HTML tags to his/her script. I think we're deviating from the subject a bit. The facts of the matter are that the OP did not ask for the HTML to be shown in entity form,. but he DID ask for the HTML to be removed, which I think I have provided the code for. With htmlentities, they're not posting HTML tags. htmlentities( ) removes HTML. Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612069 Share on other sites More sharing options...
papaface Posted August 8, 2008 Share Posted August 8, 2008 ok Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612071 Share on other sites More sharing options...
waynew Posted August 8, 2008 Share Posted August 8, 2008 We've wasted our time arguing over what car drives. :-\ Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612072 Share on other sites More sharing options...
ILYAS415 Posted August 8, 2008 Share Posted August 8, 2008 wayne reply to my message Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612073 Share on other sites More sharing options...
webguync Posted August 9, 2008 Author Share Posted August 9, 2008 sorry to cause such a stir! FWIW I did mean how to strip out the HTML code entirely, so papaface had the response that worked. I know it's an unusual question, but I just wanted to know how it was done in PHP. Link to comment https://forums.phpfreaks.com/topic/118843-removing-html-code/#findComment-612116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.