I want to remove everthing from a string except the numbers. The strings will be mostly like this, but won't always have letter at the end.
$str = 'D-6430zip';
For the above string, I want the echo results to = 6430
| SitePoint Sponsor |

I want to remove everthing from a string except the numbers. The strings will be mostly like this, but won't always have letter at the end.
$str = 'D-6430zip';
For the above string, I want the echo results to = 6430
PHP Code:<?php
$sString = 'D-6430zip';
echo $sString; #D-6430zip
$sString = preg_replace('~[^0-9]~', '', $sString); #removes anything non-numeric
echo $sString;#6430
?>
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

That is just what I wanted.
Thanks,
Samantha
Not a problem, HTH.![]()
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
can simplifiy the regex by just doing /\D/![]()

I like simple things... thanks logic_earth.
Bookmarks