kumarrohit007
Right off the assembly line
I have a problem in PHP regarding preg_match/preg_match_all funtion.
This is the sample script:
<?php
$u_agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE/i', $u_agent))
$ub = 'MSIE';
$known = array('version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
preg_match_all($pattern, $u_agent, $matches);
print_r($matches);
?>
Output(in Internet Explorer):
Array ( [0] => Array ( [0] => MSIE 6.0 ) [browser] => Array ( [0] => MSIE ) [1] => Array ( [0] => MSIE ) [version] => Array ( [0] => 6.0 ) [2] => Array ( [0] => 6.0 ) )
I am not getting line #6, particularly - '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
What these symbols and the output mean? Please relate the output and script aswell.
This is the sample script:
<?php
$u_agent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE/i', $u_agent))
$ub = 'MSIE';
$known = array('version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
preg_match_all($pattern, $u_agent, $matches);
print_r($matches);
?>
Output(in Internet Explorer):
Array ( [0] => Array ( [0] => MSIE 6.0 ) [browser] => Array ( [0] => MSIE ) [1] => Array ( [0] => MSIE ) [version] => Array ( [0] => 6.0 ) [2] => Array ( [0] => 6.0 ) )
I am not getting line #6, particularly - '#(?<browser>' . join('|', $known) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
What these symbols and the output mean? Please relate the output and script aswell.