Oh and this works for the iPod touch as well.  I’m aware that there are great mobile detection solutions out there but I was working with a client recently that has a flash logo animation on their site and unfortunately the source file was unavailable to tweak.  To accomplish this I applied a “simple fix” by using the following code to display alternate content if the visitor is using an Apple device.

<?php
if (preg_match("/iP(hone|od|ad)/i", $_SERVER['HTTP_USER_AGENT'])) {
    // Display iSpecific content
} else {
    // Display other content
}
?>
  • http://www.greenwithus.com J.P.

    Boom! Nice!

  • http://www.chrisredding.com Chris Redding

    Very useful. I’ve got a version similar to this getting Vimeo videos to work on the iphone et al.

  • Landon Miller

    Thanks Chris, I will have to check out your vimeo solution!

  • http://squaregirl.com Krystyn

    Nice. I did something similar with javascript to swap HTML5 video tags when iPad is detected.

  • http://pulse.yahoo.com/_EZRH2WK7QQMBNRTDYKAMKZVKBQ G E E K C U B E

    have you found anything else (this straight-forward) that would detect any mobile/android (handheld type) browser – in most cases i just use one mobile template. would be great to have detection consolidated into an easy to manage snippet like this.
    thanks!