PHP code organization...

From: Date: Thu, 22 Nov 2001 08:19:14 +0000
Subject: PHP code organization...
Groups: php.general 
Request: Send a blank email to php-general+get-75481@lists.php.net to get a copy of this message
Ok, this is very important to me, but I'm not sure how to explain it well. I am working on a project using PHP that supports about 6 different browsers and browser versions. All the code is in one single file for now, but I will eventually split the code up and call them using several include files. The problem is that when I start writing the code and it doesn't support a specific browser version, I customize the code with some browser sniffing...for example: <table> <tr> <td width='100'> first column </td> <?php if ($browser == "ns4") { ?> <td bgcolor="ff0000"> second column </td> <?php } elseif ($browser == "ns6") { ?> // using different field-color for this browser version... <td bgcolor='0000ff'> second column </td> <?php } else { ?> // using different field-color for this browser version... <td bgcolor='00ff00'> second column </td> <?php } ?> </tr> </table> This is not a real-world example, but it works for trying to explain my problem. The code is messy. The sniffing is done earlier and is set by $browser, which holds a value depending on which browser the user is using at the moment they access the page. I want this code to look as normal as html can possibly look, with a less ambiguous tree-like flow, in the following format for example: <table> <tr> <td width='100'> first column </td> <td bgcolor="some_color"> second column </td> </tr> </table> How would you guys organize the code to where it makes the best use of whichever browser is being used, but with less messy code? I probably haven't explained it well, but if you have any questions please let me know and I'll be more than happy to answer them. By the way, I'm a newbie at PHP, and so far I think it's the best thing that has ever happened to the web. Thanks in advance. :) Navid

« previous php.general (#75481) next »