Jump to content

Strip from text


forumnz

Recommended Posts

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&#039;s&nbsp;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>

Link to comment
https://forums.phpfreaks.com/topic/141364-strip-from-text/
Share on other sites

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&#039;s&nbsp;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 =--

Link to comment
https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739934
Share on other sites

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&#039;s&nbsp;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.

Link to comment
https://forums.phpfreaks.com/topic/141364-strip-from-text/#findComment-739996
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.