PDA

View Full Version : [PHP] Preg_match su 100%


x3d0
27-01-2010, 23:57
$string = "100%"

Voglio estrarre, in valori separati, 100 e %

Inoltre, nel caso $string = "100", voglio estrarre 100

Ho provato con
preg_match('/([0-9]*)(%)/', "100%" , $matches);
print_r($matches);

Ma mi estrae 3 valori

Array ( [0] => 100% [1] => 100 [2] => % )

kk3z
28-01-2010, 12:08
E' corretto:

If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.

x3d0
29-01-2010, 14:19
e se avessi 100.45%??