简体   繁体   中英

PHP preg_match_all returns empty arrays

I have this preg_match_all :

$cash = "hi £240";

preg_match_all("/^£?(([1-9]{1,3}(,\d{3})*(\.\d{2})?)|(0\.[1-9]\d)|(0\.0[1-9]))$/", $cash, $matches);

print_r($matches);

And the print_r returns:

Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) [3] => Array ( ) [4] => Array ( ) [5] => Array ( ) [6] => Array ( ) )

When I tried just preg_match, it didnt work at all, did I miss something?

I am searching the string for GB monetary values.

$cash = "hi £240";
preg_match_all("/£(?P<amount>\d*,?\d*\.?\d*)/",$cash,$match);

print_r($match['amount']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM