I have this code here
$search = $_SERVER['HTTP_USER_AGENT'];
The Search returns Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0
This find is inside an array
$find = '(Nexus 7) | ((Android) && (Tablet))';
This if statement is inside a foreach statement hence the break.
if(eregi($find, $search)) {
break;
}else{
$os = "Unknown";
}
and my if statment returns Unknown!! is there something wrong with my find string ((Android) && (Tablet)) or is eregi not what I want to use?
This can be accomplished using strpos()
and an if()
test:
if ( false !== strpos( $search, 'Nexus 7' ) ||
( false !== strpos( $search, 'Android' ) &&
false !== strpos( $search, 'Tablet' ) ) { ... }
Note that the 'value-and-type' test ( !==
) must be used here because strpos
will return '0' if the search term is found at the beginning of the target string.
if (!preg_match("/Nexus 7|Andriod|Tablet/", $_SERVER['HTTP_USER_AGENT']) $os = "unknown";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.