regex - PHP Regexp header (session id) -
i have following code :
$html = get_data($url); i want extract session id code, has following form :
phpsessid=aaabbb123456789;
i'd store session id (only id) in var. use regexp :
preg_match('#phpsessid=(.+?);#is', $html, $result); i want, $result tab contains 2 strings. here var_dump():
array(2) { [0]=> string(37) "phpsessid=aaabbb123456789;" [1]=> string(26) "aaabbb123456789" } i preg_match() return id, in $result[1]. should change in regexp ?
thanks
the result list of regex matches has first result being entire string. php's preg_match() guarantees well:
if matches provided, filled results of search.
$matches[0]contain text matched full pattern,$matches[1]have text matched first captured parenthesized subpattern, , on.
so can safely extract value $result[1] without worrying might change , cause warning.
Comments
Post a Comment