PHP preg_replace only numbers -


i have string , want number witch between 5 , 7 charts. here problem:

$string = "test 1 97779 test"; if(strlen(preg_replace("/[^0-9]/", "", $string)) >= 5 && strlen(preg_replace("/[^0-9]/", "", $parts[7])) <= 7) {     $var = preg_replace("/[^\d-]+/", "", $string); }  

result is: 19779, want 97779. if have suggestion glad. in advance.

your friend preg_match

if(preg_match('/\b\d{5,7}\b/', $str, $out))   $var = $out[0]; 

see demo @ eval.in


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

dataset - MPAndroidchart returning no chart Data available -

post - imageshack API cURL -