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>"; Quote Link to comment 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); ?> Quote Link to comment 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; Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
papaface Posted August 8, 2008 Share Posted August 8, 2008 ok Quote Link to comment 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. :-\ Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted August 8, 2008 Share Posted August 8, 2008 wayne reply to my message Quote Link to comment 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. Quote Link to comment 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.