Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strip all classes from p tags

Tags:

php

class

strip

I was just wondering if any one knew a function to remove ALL classes from a string in php.. Basically I only want

<p> 

tags rather than

<p class="...">

If that makes sense :)

like image 352
SoulieBaby Avatar asked Jul 23 '09 10:07

SoulieBaby


1 Answers

A fairly naive regex will probably work for you

$html=preg_replace('/class=".*?"/', '', $html);

I say naive because it would fail if your body text happened to contain class="something" for some reason!. It could be made a little more robust by looking for class="" inside angled bracketted tags if need be.

like image 117
Paul Dixon Avatar answered Oct 30 '22 12:10

Paul Dixon