get number from string in php code example
Example 1: php get only numbers from string
$str = 'In My Cart : 11 items';
$int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);
Example 2: Extract Numbers From a String in PHP
phpCopy<?php
$string = 'Sarah has 4 dolls and 6 bunnies.';
preg_match_all('!\d+!', $string, $matches);
print_r($matches);
?>