<?php header("Content-type: text/html;charset=utf-8"); $agent = getenv( "HTTP_USER_AGENT" ); $msg = ""; $patterns = array('/MSIE [0-9]+\.[0-9]+/', '/Firefox\/[0-9]+\.[0-9]+/', '/OPR\/[0-9]+\.[0-9]+/', '/Chrome\/[0-9]+\.[0-9]+/', '/[0-9]+\.[0-9]+\.[0-9]+ Safari/'); for($i=0, $len=count($patterns); $i<$len; $i++) { if (preg_match($patterns[$i], $agent, $matches, PREG_OFFSET_CAPTURE, 0)) { $msg = "お使いのブラウザは「" . $matches[0][0] . "」です。"; break; } } echo $msg; ?>
ネタ元