How to remove all non-numeric characters from a string in php?
In this post, We can remove all non-alphanumeric characters from the string with preg_replace() function in PHP.
1. Code:
<?php
function removeAllNonNumericCharacters($str){
$result = preg_replace("/[^0-9]/", "", $str);
return $result;
}
$str = "Soltuts.com 1 is2 providin3 PHP4 tutorials5";
echo(removeAllNonNumericCharacters($str));
?>
2. Example:
Input:
"Soltuts.com 1 is2 providin3 PHP4 tutorials5"
Output:
12345