Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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
Source by 3v4l.org #
 
PREVIOUS NEXT
Tagged: #php #number #string
ADD COMMENT
Topic
Name
2+6 =