Link to home
Start Free TrialLog in
Avatar of betwin
betwin

asked on

Replace HTML tag attribute values using regex & php

Hello,
I have a php function that spits out some HTML tags.

Could you help me write a regex that replaces all values of the width attribute by 300, and stores the old width in a variable.

Many thanks


<?php
$oldwidth="";
$string   = '<object width="400" height="325"><param name="movie" value="http://www.youtube.com/v/b9JAHhqV6Ko&amprel=0&ampegm=0&ampshowinfo=0&ampfs=1"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/b9JAHhqV6Ko&amprel=0&ampegm=0&ampshowinfo=0&ampfs=1" type="application/x-shockwave-flash" width="400" height="325" allowFullScreen="true" wmode="transparent"></embed></object>';
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of betwin
betwin

ASKER

Thank you very much, it works a treat :)
NP. Glad to help  : )