1$str = 'In My Cart : 11 items';
2$int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);
1phpCopy<?php
2$string = 'Sarah has 4 dolls and 6 bunnies.';
3$outputString = preg_replace('/[^0-9]/', '', $string);
4echo("The extracted numbers are: $outputString \n");
5?>
6
1phpCopy<?php
2$string = 'Sarah has 4 dolls and 6 bunnies.';
3$int = (int) filter_var($string, FILTER_SANITIZE_NUMBER_INT);
4echo("The extracted numbers are: $int \n");
5?>
6
1phpCopy<?php
2$string = 'Sarah has 4 dolls and 6 bunnies.';
3preg_match_all('!\d+!', $string, $matches);
4print_r($matches);
5?>
6