extract numbers from a string in php

Solutions on MaxInterview for extract numbers from a string in php by the best coders in the world

showing results for - "extract numbers from a string in php"
Aminata
30 Aug 2017
1$str = 'In My Cart : 11 items';
2$int = (int) filter_var($str, FILTER_SANITIZE_NUMBER_INT);
Félix
19 Oct 2018
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
Emmie
05 Jun 2018
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
Sofia
09 Nov 2018
1phpCopy<?php 
2$string = 'Sarah has 4 dolls and 6 bunnies.';
3preg_match_all('!\d+!', $string, $matches);
4print_r($matches); 
5?> 
6
queries leading to this page
php string get numbers onlyphp get all numbers from stringhow to get number from string in phpextract only numbers from string phpget only integer with phphow to get string from particular number in phpget number only in phpphp only numberhow to extract only integer from string in phpphp get only digits from stringphp only numbers from stringget number only in string using phpphp get number from stringfind only number from string phpextract integer from string in phpextract integer from string phpphp return number from stringphp get numbers parget number from string in php only numbers phpextract number after specific text phpextract specific numbers from string phpphp take out numbers from stringphp get digits from stringget only digits from string phpphp extract number from stringphp how much number from stringphp only number stringextract numbers from a string in phponly get number from string phpreturn only int characters from string phpphp returning only digits of a stringphp from numberphp keep only numbers in stringphp get only integer from stringphp get only numberstake only numbers from string phpprinting numeric value in phpphp find number near stringonly take numeric values from string phpget string numbers only phpget the number in a string phponly numeric phpget digit from string phpphp regex get only numbers from stringphp show only int from stringsphp get number from inthow to get only numbers from a string phpextraxt number from string phpshow whole number only phpphp get numeric part only from stringphp how to get number value from stringallow only string and numbers using phpget only numebr in string using phpget only integers from string phpget numbers as string phpphp parse only numbers and letters from stringexract number from string phphow to get integer from string in phpphp get 25 of numberget integers from string phpphp extract digits from stringget only integer value from string in phpextract numbers from text in phpget only numbers from string phpphp get only numbers from stringgetting only numbers from a string in phpget numeric value from string phpphp string extract numbersphp only numeric 2cphp extract only numbers from stringextract only number from string phphow to get only numeric characters from a text in phpget only integer from string phpget int from string phpextract numbers from string phpextract number from string in phpdoes get work with numeric value only in phpphp extract integer from stringphp extract numbers from stringphp parse a string for only numbershow to extract all integer for string i phphow to extract number from string in phponly get number phpphp string only numbercreate number from string phpreturn only digits from string phptake integer varues only from string in phphow to get only numeric characters from a text in a phpphp code to extract integer from stringget only number from string phpphp string only numbers and lettersextract digit from integer phpget numbers in string phpphp string only numbershow to get numbers from string in phphow to get integer value from string in phpphp get integer from stringphp leave only numbers in stringget the numeric value of a string phpget the number of a string phpnumeric string phpget numbers from text phpget only integer from string 2binteger phpphp get int from stringphp get the number from stringonly get numbers in string phpfunction return numeric value from string in phpphp code to find only integersphp get digit from stringextract int value from string phpget only digit from string phpget integer from string phpget number from string in phpget number from text phptake only number from string phpphp extract numberphp numbers from stringget only number in string phphwo to get number from string in phpget number from string phpphp get numbers only from stringgetting the number from a string phpphp get number out of stringphp only numbersphp only numbers allowedextract numer from string phpget all numbers from a string phpphp string find only numbersonly take number from variable in phpphp get numeric value from stringuse regex get number in string laravelphp get only numbers and letters from stringonly number phphow to get only number from string in phpphp string extract numberhow to take only numerc value from string in phpget numberr phpphp extract numbers for stringget number from a string phpphp check string numbers onlyextract numerics from string phphow to return whole number phpget only number from string in phpextract number from string phpphp get numbers from stringget number from string php8only grab numbers from string phpget numbers from string phpget integers only phpget only nuber in php stringget all numbers from string phpextract numbers from a string in php