removing 'width' attribute from image tag using preg_replace

my site users are using WYSWYG editor .. they insert image like
<img src="" width="500" height="200" />
I want to remove width="<some value>" and height attribute from the tag before insert data into database
is preg_replace or any other php function will help me to cut if off ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this

Open in new window

amitbravoAuthor Commented:
but this way this can remove attribute of other tags such as table , etc . i only need  to remove tag of <img src.. tag only
Then you can use something like this.
$text='<img src="" width="500" y="d" height="200" a="e" b="4" />
<table heght="200" width="678"></table>
<img src="" width="500" height="200" />';
echo preg_replace("!(<img)([^<>]+)(/>)!e","'\\1'.preg_replace('!(height|width)=\"[^\"]*\"!i','',\"\\2\").'\\3'",$text),"\n";

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.