title: PHP - Get exact iOS version from User-Agent
body: <p>I'd like to get the exact iOS version in PHP from the User-Agent. I am well aware of the possibilities with faking user-agents, but in my case, it isn't an issue.</p>
  
  <p>An normal iPhone User-Agent String looks like this:</p>
  
  <pre><code>Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_1 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0 Mobile/15C153 Safari/604.1
  </code></pre>
  
  <p>How can I extract the OS version from this? In this case it is "11_2_1". I got to be able to pull it from iPhone, iPad and iPod user-agents. It also can be X_X instead of X_X_X.</p>
  
  <p>So far I got this:</p>
  
  <pre><code>&lt;?php
  $version = preg_match('(iPad|iPhone|iphone|iPod).*?(OS |os |OS\_)(\d+
  ((_|\.)\d)?((_|\.)\d)?)', $_SERVER['HTTP_USER_AGENT']);
  echo $version;
  ?&gt;
  </code></pre>
  
  <p>However, visiting it from an iPhone shows a blank page. Can someone help me please?</p>
  
  <p>Thanks in advance.</p>