Hi Reader's,
Welcome to FindNerd, today we are going to discuss how to extract a number from a string in PHP ?
If you just want to filter the numbers out, the easiest is to use preg_replace() function.
It is very simple and easy function to use.
you can take reference of bellow example
<?php
//here define a variable of string
$str = "Hi joe! 456 how Are You? 78";
//here call preg_replace()
$get_number = preg_replace('/[^0-9]+/', '', $str);
//print $get_number variable
print_r($get_number);
?>
output will come following of above example
45678
0 Comment(s)