tags:

views:

13

answers:

1

how can I use preg_match to extract secret_password from this string? s:6:"secret_password"

A: 

If you have a colon-delimited string, it might be better to use explode(':', $string) but here is the answer using preg_match

$subject = 's:6:"secret_password"';
$pattern = '/\"[^"]+\"/';
preg_match($pattern, $subject, $matches);
print_r($matches[0]);
MikeD
yes, explodes look simpler
big ralph