title: How can `eregi()` function can be replaced in below code with `preg_match()` function?
body: <p>How can <code>eregi()</code> function can be replaced here with <code>preg_match()</code> function in below given code?</p>
  
  <pre><code>function getOS($userAgent) {
    // Create list of operating systems with operating system name as array key 
      $oses = array (
          'iPhone' =&gt; '(iPhone)',
          'Windows 3.11' =&gt; 'Win16',
          'Windows 95' =&gt; '(Windows 95)|(Win95)|(Windows_95)', // Use regular expressions as value to identify operating system
          'Windows 98' =&gt; '(Windows 98)|(Win98)',
          'Windows 2000' =&gt; '(Windows NT 5.0)|(Windows 2000)',
          'Windows XP' =&gt; '(Windows NT 5.1)|(Windows XP)',
          'Windows 2003' =&gt; '(Windows NT 5.2)',
          'Windows Vista' =&gt; '(Windows NT 6.0)|(Windows Vista)',
          'Windows 7' =&gt; '(Windows NT 6.1)|(Windows 7)',
          'Windows NT 4.0' =&gt; '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
          'Windows ME' =&gt; 'Windows ME',
          'Open BSD'=&gt;'OpenBSD',
          'Sun OS'=&gt;'SunOS',
          'Linux'=&gt;'(Linux)|(X11)',
          'Safari' =&gt; '(Safari)',
          'Macintosh'=&gt;'(Mac_PowerPC)|(Macintosh)',
          'QNX'=&gt;'QNX',
          'BeOS'=&gt;'BeOS',
          'OS/2'=&gt;'OS/2',
          'Search Bot'=&gt;'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp/cat)|(msnbot)|(ia_archiver)'
      );
  
      foreach($oses as $os=&gt;$pattern){ // Loop through $oses array
      // Use regular expressions to check operating system type
          if(eregi($pattern, $userAgent)) { // Check if a value in $oses array matches current user agent.
              return $os; // Operating system was matched so return $oses key
          }
      }
      return 'Unknown'; // Cannot find operating system so return Unknown
  }
  </code></pre>