<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.thelemur.com &#187; PHP</title>
	<atom:link href="http://blog.thelemur.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.thelemur.com</link>
	<description>Home of all things lemur</description>
	<lastBuildDate>Sun, 15 Jan 2012 19:59:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Using PHP to load browser-specific styles</title>
		<link>http://blog.thelemur.com/development-procedures/using-php-to-load-browser-specific-styles</link>
		<comments>http://blog.thelemur.com/development-procedures/using-php-to-load-browser-specific-styles#comments</comments>
		<pubDate>Fri, 27 Jun 2008 04:17:41 +0000</pubDate>
		<dc:creator>lemur</dc:creator>
				<category><![CDATA[Development Procedures]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.thelemur.com/?p=14</guid>
		<description><![CDATA[PHP allows programmers to detect the browser and operating system for every page visitor. This capability isn&#8217;t limited to PHP, but that&#8217;s what we&#8217;ll be working with today. This article is a proposed workflow for solving browser-specific CSS bugs. Potential Problems Browser detection is not bulletproof since users can change their browser name string, firewalls [...]]]></description>
			<content:encoded><![CDATA[<p>PHP allows programmers to detect the browser and operating system for every page visitor. This capability isn&#8217;t limited to PHP, but that&#8217;s what we&#8217;ll be working with today. This article is a proposed workflow for solving browser-specific CSS bugs.</p>
<p><span id="more-14"></span></p>
<h3>Potential Problems</h3>
<p>Browser detection is not bulletproof since users can change their browser name string, firewalls may prevent browser data from passing through, and software builders change their browser ID formats. Since these are the exceptions and not the rule-it&#8217;s worth attempting to customize the page presentation to your visitors&#8217; browser.</p>
<h3>Approach</h3>
<ol>
<li>Create individual stylesheets for different browsers and browser versions</li>
<li>Use PHP to detect the current browser and browser version</li>
<li>Load base stylesheets first</li>
<li>Load browser-specific styles after the base styles</li>
</ol>
<p>The order of steps 3 and 4 are critical. We&#8217;re trying to overwrite the base styles so they must be included first in the HTML header.</p>
<h3>Detecting the Browser Version</h3>
<p>At the very least you&#8217;ll need to retrieve the browser name. If compatibility requirements are strict you&#8217;ll want the version and revision numbers too. Once you&#8217;ve chosen a detection script you&#8217;re ready to move on.</p>
<p>Instead of retyping source, I will now point you to <a title="http://www.hudzilla.org/phpbook/read.php/16_5_0" href="http://www.hudzilla.org/phpbook/read.php/16_5_0" target="_blank">this site</a> which uses PHP&#8217;s <code>get_browser()</code> function. This page has a dedicated author and a history of updates dating back to 1998.</p>
<p>I recommend using get_browser() but if you don&#8217;t want to modify your PHP setup you are in luck. There are enough open-source detection scripts on the web to save you the trouble of writing your own. When you find a script be sure to check its release date.</p>
<p>An open-source script will have the same approach as the browser capability approach linked above.</p>
<h3>Suggestions</h3>
<ul>
<li>If you&#8217;re aiming for IE and Firefox it&#8217;s probably simpler to keep all your files in one ./css/ directory</li>
<li>Use a folder structure like the one below if you have many browser-specific CSS files.<br />
<img style="border: 1px solid black;" src="http://blog.thelemur.com/files/css/css_folders.png" alt="" width="119" height="88" /></li>
</ul>
<ul>
<li>If you&#8217;re switching approaches mid-project be sure to add relative paths to your CSS files!</li>
</ul>
<h3>References</h3>
<p><a href="http://www.hudzilla.org/phpbook/read.php/16_5_0" target="_blank">http://www.hudzilla.org/phpbook/read.php/16_5_0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.thelemur.com/development-procedures/using-php-to-load-browser-specific-styles/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.328 seconds -->

