Tags

,

so if you have number of string like

$numberString = +1-800-123-(456);

after calling through function clean($numberString);

Result: 1800123456

function clean($string) {
	$string = str_replace(' ', '', $string); // Replaces all spaces.
	$string = preg_replace('/([^A-Za-z0-9\-])/', '', $string); // Removes special chars.
	return preg_replace('/-+/', '', $string); // Replaces multiple hyphens with single one.
}
Advertisements