how to get only the numbers from a string in php code example
Example 1: php keep only numbers in string
$str = preg_replace('/[^0-9.]+/', '', $str);
Example 2: get numbers from string php
phpCopy<?php
$string = 'Sarah has 4 dolls and 6 bunnies.';
preg_match_all('!\d+!', $string, $matches);
print_r($matches);
?>