Avatar of Jeff
Jeff
 asked on

Strip HTML Entities and convert <br> Entity to \n

I am pulling info out of a database that has html entities. I need to convert <br> to \n and remove all other entities to be able to add content to an email body without the html.

12:00pm - Some &amp; Text goes here &lt;p&gt;&lt;strong&gt;TUESDAY - NOVEMBER 1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;12:00PM - 5:00PM&lt;/strong&gt;&lt;br /&gt;

Open in new window

PHPHTML

Avatar of undefined
Last Comment
Jeff

8/22/2022 - Mon
Julian Hansen

Take a look at strip_tags()

You would do the following
$html = strip_tags($html, '<br>');
$html = preg_replace('/\<br\s*\/?\>/',"\n", $html);

Open in new window

ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jeff

ASKER
Julian, Thanks for the quick response. I couldn't quite get the solution to work. The entities needed to be converted to HTML first, then strip and replace.

Ray, Your solution worked perfectly. Thanks you.
Jeff

ASKER
Thanks Ray.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck