You really look at a couple of different things here ...
The html tags tell the browser how to handle certain situations, while the PHP script detects the mobile browser and the script runs on the server.
Each has its own ... well, you probably end up using a combination of the two.
I usually detect mobile browsers using the server side of the script, and then output html tags (e.g. the ones you specified) if a mobile browser is detected.
...
1)
2) PHP ( )
3) , CSS, .. CSS.