Answers for "php get number in string"

PHP
0

php get number from string

function get_numerics ($str) {
    preg_match_all('/\d+/', $str, $matches);
    return $matches[0];
}

// this function will return an array of number

$str = "3 dogs were running!";
echo (get_numerics($str)[0]); 

// output 3
Posted by: Guest on August-24-2021
0

get numbers from string php

phpCopy<?php 
$string = 'Sarah has 4 dolls and 6 bunnies.';
preg_match_all('!\d+!', $string, $matches);
print_r($matches); 
?>
Posted by: Guest on April-23-2021

Code answers related to "php get number in string"

Browse Popular Code Answers by Language