0

Is there a way to only display the iOS firmware in browser thru PHP?

I have tried this

echo $agent = $_SERVER["HTTP_USER_AGENT"]; 

but then al info is shown and i want only to display the iOS version. This is what i get if i use that code:

Mozilla/5.0 (iPhone; CPU OS X 7_0_2) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 mobile Safari/536.30.1 etc etc...

Is there any way to display this like: 7.0.2 only

1

1 Answer 1

0

Try this

<?php

$text =  $_SERVER["HTTP_USER_AGENT"]; 

preg_match('/OS X ([_0-9]+)/', $text, $res);

$version = isset($res[1])?str_replace('_','.',$res[1]):null;

var_dump($version);

/* EOF */
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, id did exactly as descriped but for now i have an output like: string(5)"7.0.2" and i don't know for what reason "string(5)" is in the output.
You can also write echo $version; Than you get only the string, without information about the variable itself. See here: php.net/manual/de/function.var-dump.php

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.