Link to home
Start Free TrialLog in
Avatar of Nura111
Nura111

asked on

mobile site version by changing css

I Want to create a mobile version of my php website I want to just change the style sheet of the website for the mobile version when I detect a mobile USER AGENT I want to include a different style sheet is there anyway to do it in php?
Avatar of re-searcher
re-searcher
Flag of United States of America image

yes, it's possible if you're using template engine like smarty or your own template.

you can get user agent with following code:
$agent = $_SERVER['HTTP_USER_AGENT']

Open in new window


here is sample for checking Mozilla browser:
if(preg_match('/^Mozilla\/.*?Gecko/i',$agent)){
     /// using custom css
    echo 'mozilla.css';
}

Open in new window


I recommend which you read this article (it's contain mobile user-agents):
http://www.zytrax.com/tech/web/mobile_ids.html

I hope it's be useful.
ASKER CERTIFIED SOLUTION
Avatar of re-searcher
re-searcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nura111
Nura111

ASKER

Thank you all for the help a few question:
A. just to make sure there is nothing to do about the inline style right?
B. does eching the css is basically the same as using the <link rel  ?
You can put style sheet information into the HTML inline.  I like to do this when testing because the browser does not cache the inline style.
Avatar of Nura111

ASKER

I mean as for the style information that are inline  I cant change it in the mobile version throw the style sheet right?
Nura,

you can do everythings when you detect you visitor are from which agent, mobile or pc browser.

standard page should not contain in-line styles. it's better you put all of them into an css file and then do like steps which i told you in my previous post.
Avatar of Nura111

ASKER

what id the media="handheld and media=screen for?
Avatar of Nura111

ASKER

Is xsly has anything to do with what im trying to do?
Avatar of Nura111

ASKER

XSLT
Can i ask what exactly you need?

XSLT is for transforming XML documents into XHTML documents or to other XML documents.
 07fig01.gif
Avatar of Nura111

ASKER

I need to optimize my website to mobile
best way is using specified template for each mobile version like symbian, iphone, blackberry.

read this article -> http://www.smashingmagazine.com/2010/11/03/how-to-build-a-mobile-website/

best way for optimization is optimize your css and images and html contents.
+ decrease size of pictures with php image resizer class
+ use short code instead of normal codes in css. i.e instead of #FFFFFF use #FFF
+ for best and professional appearance you should specify custom template for each mobile version, one of best solutions for this is Smarty Template Engine or another template engines.
+ test your template with adobe live browser
To anyone who happens across the assisted solution at ID:36973392, note that the href= values should almost certainly be different if you want to have different CSS for the desktop and the mobile device.  The correct example of the code is shown in the code snippet at ID:36973444.
Avatar of Nura111

ASKER

Oh sorry I chose the wrong one Can I change it somehow?
i think nope, it's not possible for you.
just moderators can change this.