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];
\b
matches word boundary\d{5,7}
in between 5 7 digits \d
Comments
Post a Comment