PHP Regex Leave Only Numbers

Can be used when you want to clean telephone numbers

// test string
$str = ' +20 875-458-5555';
// remove all but digits
$num = preg_replace('/[^0-9]/', '', $str);
// show new string
echo $num;

Usage

Use as is


Comments

Add your comment

Need a COVID-19 website?
Preview
Or
Contact us

No, thanks!