I have a simple script, in which I am trying to pull the browser type out of an agent string. This should be horribly easy but I cant seem to pull it off.

I am using regex, and have tried a dizzying array of different configurations. The only response I am getting from the script is the default case, that being unknown. In using my own user agent string, I know the word Firefox is within the string but cant capture it.


if (isset($agent)){
    case 1:
    if (preg_match('/(?:MSIE 3)/', $agent)){
        $browser = "MSIE 3";
    case 2:
    if (preg_match('/(?:MSIE 4)/', $agent)){
        $browser = "MSIE 4";
    case 3:
    if (preg_match('/(?:MSIE 5)/', $agent)){
        $browser = "MSIE 5";
    } break;
    case 4:
    if (preg_match('/(?:MSIE 6)/', $agent)){
        $browser = "MSIE 6";
    case 5:
    if (preg_match('/(?:MSIE 7)/', $agent)){
        $browser = "MSIE 7";
    case 6:
    if (preg_match('/?:(MSIE 8)/', $agent)){
        $browser = "MSIE 8";
    } break;
    case 7:
    if (preg_match('/(?:Opera)/', $agent)){
        $browser = "Opera";
    case 8:
    if (preg_match('/(?:Chrome)/', $agent)){
        $browser = "Chrome";
    case 9:
    if (preg_match('/(?:Safari)/', $agent)){
        $browser = "Safari";
    case 10:
    if (preg_match('/^(?:(Firefox))$/', $agent)){
        $browser = "Firefox";        
    $browser = "Unknown"; 
I have tried the break within the if statement and outside. The script from here just goes on to enter the browser into the database.

Any thoughts?