forumnz Posted January 18, 2009 Share Posted January 18, 2009 I have text from a database that is riddled with unwanted code. As seen below. How can I remove all but the text? Here is an example of what is there: <div><font size="4">Brand New Item With Tags</font></div><div><font size="4"></font></div><div><font size="4">This item is a Brand New Abercrombie and Fitch Women's Yellow Hoody size Medium.</font></div><div><font size="4"></font></div><div><font size="4">Authentic vintage inspired sportswear and sexy effortless style combine to create a signture American brand with timeless appeal.</font></div><div><font size="4"></font></div><div><font size="4">Size diamentions are as follows: front underarm chest 48 cm, shoulder to waist 61cm, underarm to sleave 56cm</font></div><div><font size="4">This style is tight fitting so please pay close attention to the measurements for a good fit.</font></div><div><font size="4"></font></div><div><font size="4">Please feel free to ask any questions about this sweater.</font></div> Quote Link to comment https://forums.phpfreaks.com/topic/141364-strip-from-text/ Share on other sites More sharing options...
Mark Baker Posted January 18, 2009 Share Posted January 18, 2009 Try a combination of html_entity_decode() to revert <div> back to <div> then striptags() Quote Link to comment https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739924 Share on other sites More sharing options...
tronicsmasta Posted January 18, 2009 Share Posted January 18, 2009 I am curious on why you put all those HTML tags into your database in the first place... $dbstring = "<div><font size="4">Brand New Item With Tags</font></div><div><font size="4"></font></div><div><font size="4">This item is a Brand New Abercrombie and Fitch Women's Yellow Hoody size Medium.</font></div><div><font size="4"></font></div><div><font size="4">Authentic vintage inspired sportswear and sexy effortless style combine to create a signture American brand with timeless appeal.</font></div><div><font size="4"></font></div><div><font size="4">Size diamentions are as follows: front underarm chest 48 cm, shoulder to waist 61cm, underarm to sleave 56cm</font></div><div><font size="4">This style is tight fitting so please pay close attention to the measurements for a good fit.</font></div><div><font size="4"></font></div><div><font size="4">Please feel free to ask any questions about this sweater.</font></div>"; $decodedwithHTML = html_entity_decode($dbstring, ENT_QUOTES ); $completelydecoded = strip_tags($decoded); --= edit for mistake =-- Quote Link to comment https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739934 Share on other sites More sharing options...
forumnz Posted January 18, 2009 Author Share Posted January 18, 2009 Thanks! Only problem.. it still leaves <DIV>.. does that caps matter? Why doesn't it remove them? Quote Link to comment https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739935 Share on other sites More sharing options...
forumnz Posted January 18, 2009 Author Share Posted January 18, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739992 Share on other sites More sharing options...
premiso Posted January 18, 2009 Share Posted January 18, 2009 Try it without the ENT_QUOTES option. <?php $dbstring = "<div><font size="4">Brand New Item With Tags</font></div><div><font size="4"></font></div><div><font size="4">This item is a Brand New Abercrombie and Fitch Women's Yellow Hoody size Medium.</font></div><div><font size="4"></font></div><div><font size="4">Authentic vintage inspired sportswear and sexy effortless style combine to create a signture American brand with timeless appeal.</font></div><div><font size="4"></font></div><div><font size="4">Size diamentions are as follows: front underarm chest 48 cm, shoulder to waist 61cm, underarm to sleave 56cm</font></div><div><font size="4">This style is tight fitting so please pay close attention to the measurements for a good fit.</font></div><div><font size="4"></font></div><div><font size="4">Please feel free to ask any questions about this sweater.</font></div>"; $decodedwithHTML = html_entity_decode($dbstring); $completelydecoded = strip_tags($decodedwithHTML); echo $completelydecoded; die(); ?> I tested the above code and it worked for me. EDIT: It also works with the ENT_QUOTES on m system, just an FYI. Quote Link to comment https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739996 Share on other sites More sharing options...
kenrbnsn Posted January 18, 2009 Share Posted January 18, 2009 The code above does not leave any tags. Check your code. Ken Quote Link to comment https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739999 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.