Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.