the second question isn't related to php, so not sure on that, since php is my area, for the most part.
As for the code, there are several problems. I suppose that the line break after the if followed by a semicolon might work, but if you need multiple lines, so it like: if (...) {......}, surrounding the next few lines in brackets.
The main issue is that mozilla is not something standalone in PHP... it needs to be a string. So... 'mozilla', if nothing else. Here's a better way of trying it, though no browser detection is flawless.
PHP Code:
$browser = strtolower($browser);
if (strpos($browser,'mozilla') !== FALSE) {
echo '<link href="style.css" rel="stylesheet" type="text/css" />';
}
else
echo '<link href="style2.css" rel="stylesheet" type="text/css" />';
}
PHP Code:
<?php
//....
$browser = strtolower($browser); //convert the user agent string to lowercase
//now MOZILLA = Mozilla = mozilla... etc.
if (strpos($browser,'mozilla') !== FALSE) { //if 'mozilla' exists within $browser
//! means 'not', === means exactly equal to*, so !== means is not exactly equal to FALSE
//*== is equal to, but it sees 0, '' and FALSE as the same, so === seperates by type as well.
echo '<link href="style.css" rel="stylesheet" type="text/css" />'; //output style1
} //close if
else { //else with bracket
echo '<link href="style2.css" rel="stylesheet" type="text/css" />'; //output style2
} //close else
//....
?>
The text can't just sit there either... it needs to be output (echo function) and be inside quotes. (" is fine, but ' works, since you have double in the string. If you needed to use ", then you'd need to use, for example, href=\"style2.css\".... to escape the quotes in that.)
Bookmarks