note 52213 added to function.get-browser

From: Date: Sun, 24 Apr 2005 17:19:11 +0000
Subject: note 52213 added to function.get-browser
Groups: php.notes 
Request: Send a blank email to php-notes+get-88497@lists.php.net to get a copy of this message
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! ---- Manual Page -- http://www.php.net/manual/en/function.get-browser.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52213 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52213&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52213&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52213&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52213&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52213&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52213&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88497) next »