{"id":920,"date":"2012-10-15T16:28:22","date_gmt":"2012-10-15T07:28:22","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=920"},"modified":"2012-10-15T17:39:08","modified_gmt":"2012-10-15T08:39:08","slug":"how-to-write-browser-specific-html-css-in-php","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/how-to-write-browser-specific-html-css-in-php\/","title":{"rendered":"How to write <strong>Browser Specific HTML CSS in PHP<\/strong>"},"content":{"rendered":"<p>Here is code which <a href=\"https:\/\/www.santoshkori.com\/blog\/category\/web-design\/web-designer\/\">Web designer<\/a> and <a href=\"https:\/\/www.santoshkori.com\/blog\/category\/web-development\/web-developer\/\">web developer<\/a> can use to<a href=\"https:\/\/www.santoshkori.com\/blog\/web-development\/cross-browser-compatibility\/how-to-write-browser-specific-html-css-in-php\/\" target=\"_blank\"> make some code browser specific only in php<\/a>. Many times <a href=\"https:\/\/www.santoshkori.com\/blog\/category\/web-design\/web-designer\/\">Web designer<\/a> and <a href=\"https:\/\/www.santoshkori.com\/blog\/category\/web-development\/web-developer\/\">web developer<\/a>\u00a0require to put in <a href=\"https:\/\/www.santoshkori.com\/blog\/web-development\/cross-browser-compatibility\/how-to-write-browser-specific-html-css-in-php\/\" target=\"_blank\">browser-specific HTML \/ CSS<\/a> in your files, because most often the pages are rendered differently (esp. IE). You can detect what browser the user is using with the help of PHP.<\/p>\n<p><a href=\"http:\/\/santoshkori.com\/browser-specific-htmls-css.php\" target=\"_blank\" rel=\"noopener\">Demo:\u00a0<em><strong>Browser Specific HTML CSS in PHP<\/strong><\/em><\/a><\/p>\n<p><!--more-->In your PHP file, put the following code first:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php \u00a0\r\n$msie = strpos($_SERVER&#x5B;&quot;HTTP_USER_AGENT&quot;], 'MSIE') ? true : false; \u00a0\r\n$firefox = strpos($_SERVER&#x5B;&quot;HTTP_USER_AGENT&quot;], 'Firefox') ? true : false; \u00a0\r\n$safari = strpos($_SERVER&#x5B;&quot;HTTP_USER_AGENT&quot;], 'Safari') ? true : false; \u00a0\r\n$chrome = strpos($_SERVER&#x5B;&quot;HTTP_USER_AGENT&quot;], 'Chrome') ? true : false; ?&gt;\r\n<\/pre>\n<p>And use where you want to execute code based on browser<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;!--?php\r\n\/\/Firefox\r\nif ($firefox) {\r\necho 'you are using Firefox!';\r\necho '&lt;br ?--&gt;';\r\n}\r\n\r\n\/\/ Safari or Chrome. Both use the same engine - webkit\r\nif ($safari || $chrome) {\r\necho 'you are using a webkit powered browser';\r\necho '\r\n';\r\n}\r\n\r\n\/\/ IE\r\nif ($msie) {\r\necho '\r\nyou are using Internet Explorer\r\n';\r\necho '\r\n';\r\n}\r\n\r\n\/\/ Not IE and for all other browsers\r\nif (!$msie) {\r\necho '\r\nyou are not using Internet Explorer\r\n';\r\necho '\r\n';\r\n}\r\n\r\n?&gt;\r\n<\/pre>\n<p>If you are looking for IE-only conditional statements, refer <a title=\"IE-only conditional statements\" href=\"http:\/\/www.quirksmode.org\/css\/condcom.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.quirksmode.org\/css\/condcom.html<\/a><\/p>\n<p>Other useful resources:<\/p>\n<p><a href=\"http:\/\/php.net\/manual\/en\/reserved.variables.server.php\" target=\"_blank\" rel=\"noopener\">http:\/\/php.net\/manual\/en\/reserved.variables.server.php<\/a><br \/>\n<a href=\"http:\/\/php.net\/manual\/en\/function.get-browser.php\" target=\"_blank\" rel=\"noopener\">http:\/\/php.net\/manual\/en\/function.get-browser.php<\/a><br \/>\n<a href=\"http:\/\/php.net\/manual\/es\/function.get-browser.php\" target=\"_blank\" rel=\"noopener\">http:\/\/php.net\/manual\/es\/function.get-browser.php<\/a><br \/>\n<a href=\"http:\/\/w3resource.com\/php\/super-variables\/$_SERVER.php\" target=\"_blank\" rel=\"noopener\">http:\/\/w3resource.com\/php\/super-variables\/$_SERVER.php<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is code which Web designer and web developer can use to make some code browser specific only in php. Many times Web designer and web developer\u00a0require to put in browser-specific HTML \/ CSS in your files, because most often the pages are rendered differently (esp. IE). You can detect what browser the user is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,14],"tags":[438,440,437,441,442,445,443,444,439],"class_list":["post-920","post","type-post","status-publish","format-standard","hentry","category-cross-browser-compatibility","category-web-development","tag-browser-specific-html-css","tag-browser-specific-html-css-only-for-firefox","tag-how-to-write-browser-specific-html-css-in-php","tag-html-css-code-only-for-firefox","tag-php-browser-specific-html-css-only-for-firefox","tag-php-browser-specific-html-css-only-for-google-chrome","tag-php-browser-specific-html-css-only-for-ie","tag-php-browser-specific-html-css-only-for-safari","tag-php-for-browser-specific-html-css"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=920"}],"version-history":[{"count":15,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/920\/revisions"}],"predecessor-version":[{"id":927,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/920\/revisions\/927"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}