Answers for "how to get number from string php"

PHP
2

Extract Numbers From a String in PHP

phpCopy<?php 
$string = 'Sarah has 4 dolls and 6 bunnies.';
$outputString = preg_replace('/[^0-9]/', '', $string);  
echo("The extracted numbers are: $outputString \n"); 
?>
Posted by: Guest on April-23-2021
2

php get only numbers from string

$str = 'In My Cart : 11 items';
$int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);
Posted by: Guest on November-24-2020

Code answers related to "how to get number from string php"

Browse Popular Code Answers by Language