Using different stylesheets + generating HTML in PHP (how to)?

This is a discussion on Using different stylesheets + generating HTML in PHP (how to)? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I have spent the last few days trying to create a tableless web page, using CSS only for layout. I ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008
Ronald Raygun
 
Posts: n/a
Default Using different stylesheets + generating HTML in PHP (how to)?

I have spent the last few days trying to create a tableless web page,
using CSS only for layout. I have finally given up. My current css file
works fine for IE - but looks terrible in Netsacpe and Firefox. if I fix
the issue so that it works for Netscape/Firefox, then the page looks
like crap in IE.

I have finally decided to use two different style sheets (one is a minor
modification of teh other),l and generate the HTML page dynamically =-
and use a link to the appropriate stylesheet - depending on the UA
(browser) making teh request for the page.

The (simplified) logic is something like this :

$user_agent = get_user_agent();
if ($user_agent == IEXPLORER)
generate_Iexplorer_page();
else
generate_mozilla_page();


I am new to PHP (I'm a C++ programmer), so I would appreciate it if
someone could show me how to do the following:

1). Write a function to determine the UA (user agent - i.e. browser) type
2). generate html page with the appropriate css file link.

For the purposes for the code snippet, you can assume that the (path)
names of the css files are :

.../mozilla.css (css for mozilla browsers)
.../explorer.css (css for Iexplorer browsers)

Also please assume that the HTML page to be genrated consists of teh ff
simple HTML:

<html>
<head>
<title>This is a test</title>
<link rel="stylesheet" type="text/css" href="xxx.css" />
</head>
<body>Some text goes here ...</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 04-09-2008
Floortje
 
Posts: n/a
Default Re: Using different stylesheets + generating HTML in PHP (how to)?

> I am new to PHP (I'm a C++ programmer), so I would appreciate it if
> someone could show me how to do the following:




> 1). Write a function to determine the UA (user agent - i.e. browser) type


somethin like
$cssfile = (stristr($_SERVER['HTTP_USER_AGENT','msie'))?'ie.css':'ff.css';


> 2). generate html page with the appropriate css file link.


> <html>
> <head>
> <title>This is a test</title>


<link rel="stylesheet" type="text/css" href="<?php echo $cssfile; ?>" />


> </head>
> <body>Some text goes here ...</body>
> </html>

Reply With Quote
  #3 (permalink)  
Old 04-10-2008
Ronald Raygun
 
Posts: n/a
Default Re: Using different stylesheets + generating HTML in PHP (how to)?



Floortje wrote:

> > I am new to PHP (I'm a C++ programmer), so I would appreciate it if

>
>> someone could show me how to do the following:

>
>
>
>
>> 1). Write a function to determine the UA (user agent - i.e. browser) type

>
>
> somethin like
> $cssfile = (stristr($_SERVER['HTTP_USER_AGENT','msie'))?'ie.css':'ff.css';
>
>
>> 2). generate html page with the appropriate css file link.

>
>
>> <html>
>> <head>
>> <title>This is a test</title>

>
>
> <link rel="stylesheet" type="text/css" href="<?php echo $cssfile; ?>" />
>
>
>> </head>
>> <body>Some text goes here ...</body>
>> </html>


Cool - thanks very much !
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:38 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0