extract number out of a sytle attribute

bachstein
bachstein used Ask the Experts™
on
Hello

Could someone help me with this? I want to get the number out of a style width rule, for instance

if I have
style="width120px"; 

Open in new window


I want to get that 120 . I have the string in my PHP code.

like this
$var = 'style = "width:120px" ';

Open in new window

so basically what I want is to take this variable $var apply a regular expression to it ,  and the the 120 back


Cheers



 
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

$string = 'Hello, there are 29 messages waiting for you';
$number = preg_replace("/[^0-9]/", '', $string); // ditch anything that is not a number
That will strip anything that isn't 0-9
sorry i should rephrase my previous post. this will strip anything that isnt 0-9 per character comparison.

456456 would still be recognized.

Author

Commented:
It worked. Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial