Código php:
Ver original
<?php function ObtenerNavegador($user_agent) { 'Opera' => 'Opera', 'Mozilla Firefox'=> '(Firebird)|(Firefox)', 'Galeon' => 'Galeon', 'Mozilla'=>'Gecko', 'MyIE'=>'MyIE', 'Lynx' => 'Lynx', 'Netscape' => '(Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79)', 'Konqueror'=>'Konqueror', 'Internet Explorer 7' => '(MSIE 7\.[0-9]+)', 'Internet Explorer 6' => '(MSIE 6\.[0-9]+)', 'Internet Explorer 5' => '(MSIE 5\.[0-9]+)', 'Internet Explorer 4' => '(MSIE 4\.[0-9]+)', ); foreach($navegadores as $navegador=>$pattern){ return $navegador; } return "desconocido"; } echo ObtenerNavegador($_SERVER['HTTP_USER_AGENT']); ?>
Sin embargo, eregi ha sido "deprecated" en la versión 5.3 y de eliminará en la versión 6, el sustituto se supone que es preg_match, pero al cambiarlo me aparecen estos errores...
Cita:
Creo que los errores son por las expresiones regulares, pero no le encuentro sentido y estoy algo atascado.Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Unknown modifier '|' in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Unknown modifier '|' in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
desconocido
Warning: preg_match() [function.preg-match]: Unknown modifier '|' in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Unknown modifier '|' in C:\wamp\www\navegador.php on line 19
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\navegador.php on line 19
desconocido
Vale, arreglado, las expresiones regulares todas tenían que estar encerredas entre (..) tal que así:
Código php:
Ver original
<?php function ObtenerNavegador($user_agent){ 'Opera' => '(Opera)', 'Mozilla Firefox'=> '((Firebird)|(Firefox))', 'Galeon' => '(Galeon)', 'Mozilla'=>'(Gecko)', 'MyIE'=>'(MyIE)', 'Lynx' => '(Lynx)', 'Netscape' => '((Mozilla/4\.75)|(Netscape6)|(Mozilla/4\.08)|(Mozilla/4\.5)|(Mozilla/4\.6)|(Mozilla/4\.79))', 'Konqueror'=>'(Konqueror)', 'Internet Explorer 7' => '(MSIE 7\.[0-9]+)', 'Internet Explorer 6' => '(MSIE 6\.[0-9]+)', 'Internet Explorer 5' => '(MSIE 5\.[0-9]+)', 'Internet Explorer 4' => '(MSIE 4\.[0-9]+)', ); foreach($navegadores as $navegador=>$pattern){ return $navegador; } return "desconocido"; } echo ObtenerNavegador($_SERVER['HTTP_USER_AGENT']); ?>