note 52213 deleted from function.get-browser by nlopess

From: Date: Sun, 24 Apr 2005 18:14:08 +0000
Subject: note 52213 deleted from function.get-browser by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-88500@lists.php.net to get a copy of this message
Note Submitter: lampios at prodigy dot net dot mx ---- tectonik's function works great and is exactly what i needed nevertheless it can only display the navigator's version if it has a numeric format. Im using Firefox v 1.0.3 but it only displayed 1.0 so I created a little function wich makes this function to display the correct version. <? function validaContenido ( $cadena, $validacion ) { $lCadena = strlen ( $cadena ); $lValidacion = strlen ( $validacion ); for ( $i = 0; $i < $lCadena; $i++ ) { for ( $j = 0; $j < $lValidacion; $j++ ) { if ( $cadena[$i] == $validacion[$j] ) break; if ( ( $j == $lValidacion - 1 ) && ( $cadena[$i] != $validacion[$j] ) ) return false; } } return true; } ?> now you use this function instead of is_numeric so the line will look like this: <? ... //if ( is_numeric ( $GLOBALS ["ver"] . $s ) ) if ( validaContenido ( $GLOBALS["ver"] . $s, ".0123456789" ) ) ... ?> Everything will end up looking like this: <? function validaContenido ( $cadena, $validacion ) { $lCadena = strlen ( $cadena ); $lValidacion = strlen ( $validacion ); for ( $i = 0; $i < $lCadena; $i++ ) { for ( $j = 0; $j < $lValidacion; $j++ ) { if ( $cadena[$i] == $validacion[$j] ) break; if ( ( $j == $lValidacion - 1 ) && ( $cadena[$i] != $validacion[$j] ) ) return false; } } return true; } function detectaBrowser () { $navegadores = "mozilla msie gecko firefox "; $navegadores.= "konqueror safari netscape navigator "; $navegadores.= "opera mosaic lynx amaya omniweb"; $arregloNavegadores = split ( " ", $navegadores ); $navegadorUsuario = strToLower( $_SERVER['HTTP_USER_AGENT'] ); $longitudNU = strlen( $navegadorUsuario ); for ( $i = 0; $i < count( $arregloNavegadores ); $i++ ) { $navegador = $arregloNavegadores[$i]; $nombreNavegador = stristr( $navegadorUsuario, $navegador ); if ( strlen ( $nombreNavegador ) > 0 ) { $info["ver"] = ""; $info["nav"] = $navegador; $j = strpos ( $navegadorUsuario, $info["nav"] ) + $nombreNavegador + strlen ( $info["nav"] ) + 1; for ( ; $j <= $longitudNU; $j++ ) { $s = substr ( $navegadorUsuario, $j, 1); if ( validaContenido ( $info["ver"] . $s, "0123456789." ) ) $info["ver"] .= $s; else break; } } } return $info; } ?> Now for example if you use a Firefox 1.0.3 browser it will display 1.0.3 instead of only 1.0 Hope it will be as useful for you as it was for me!

« previous php.notes (#88500) next »