I posted this question on another list and received a response consisting of
potentially helpful code.  It has not been tested on my end, but I thought
I'd pass the information along.

Share the wealth.



dwalker wrote:
> What is the easiest method of determining how and when to implement
> browser
> specific  external style sheets???  I've been working on a site for
> several months now, and I discovered that the site looks pretty decent
> within IE ,
> but is less than decent within Netscape.   Do you  create one external
> style
> sheet for one browser and then create one for the other??  Or is it
> possible to do both at the same time without loosing focus??

Assuming you want to go ahead and do multiple style sheets:
One idea is to head on over to a big site which does this (i think cnn.com
does, but i only say that because i always see Netscape-specific banners
and such) and grab the different style sheets (by browsing it with
different browsers or changing the id of your browser, as Opera and
Konqueror allow for). i work for an internet company and can say that
Netscape gives our web designers no end of grief, and it's about impossible
to make something look good in Netscape 4.x.

Below are some functions which might help you in determining which style
sheet you want to show. Using those it becomes a simple matter of including
a style sheet named r_get_browser_name().".css".



function r_get_browser_name() {
  /* Get the Browser data */

    $browsers = array();
  $browsers['MSIE'] = "!MSIE!";
  $browsers['Konqueror'] = "!Konqueror!";
  $browsers['Lynx'] = "!Lynx!";
  $browsers['Opera'] = "!Opera!";
  $browsers['WebTV'] = "!WebTV!";
  $browsers['Bot'] = "/bot|Slurp|Infoseek|Spider|Google/";
  $browsers['Netscape'] = ",(Mozilla\/4|Nav|Gold|Netscape),";
  $browsers['Mozilla'] = "!Mozilla!";

  $browser = "Other";
  $agent = r_find_var( 'HTTP_USER_AGENT' );
  # echo "agent=[$agent]<br>";
  while( list($k,$v) = each( $browsers ) ) {
    if( ! preg_match( $v, $agent ) ) continue;
    $browser = $k;
    #  r_debug_log( basename(__FILE__),__LINE__,": [$browser]: regex = $v.
Agent=[$agent]" );
    #echo "browser match: browser=[$browser]: ";
    #echo "v=$v<br>k=$k<br>";
    break;
  }
  #echo "<b>browser=[$browser]</b><br>";
  return $browser;
}

function r_get_browser_os() {
  /* Get the Operating System data */
    $oses = array();
  $oses['Windows'] = "!Win!";
  $oses["OS/2"] = "!OS/2!";
  $oses['Mac'] = "!Mac|PPC!";
  $oses['Linux'] = "!Linux!";
  $oses['FreeBSD'] = "!FreeBSD!";
  $oses['SunOS'] = "!SunOS!";
  $oses['IRIX'] = "!IRIX!";
  $oses['BeOS'] = "!BeOS!";
  $oses['AIX'] = "!AIX!";

  $os = "Other";
  $agent = r_find_var( 'HTTP_USER_AGENT' );
  while( list($k,$v) = each( $oses ) ) {
    if( ! preg_match( $v, $agent ) ) continue;
    $os = $k;
    #echo "agent=[$agent]<br>OS match: OS=[$os]: key=[$k] pattern=[$v]<br>";
    break;
  }
  #echo "<b>OS=[$os]</b><br>";
  return $os;
}

function &r_find_var( $var, $defaultval = null ) {
foreach( array(
                $GLOBALS,
                $GLOBALS['HTTP_POST_VARS'],
                $GLOBALS['HTTP_GET_VARS'],
                $GLOBALS['HTTP_SERVER_VARS'],
                $GLOBALS['HTTP_COOKIE_VARS']
               )
           as $ar ) {
    if( isset( $ar[$var] ) ) return $ar[$var];
  }
  return $defaultval;
}


----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to