How to write the following in PHP:
IF current page’s name is
pagex.php
THEN please load these additional CSS rules:
#DIVS { color:#FFF }
IF current page’s name isanotherpage.php
THEN please load following CSS rules:
#DIVS { color: #000 }
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP has some “magic constants” that you can inspect to get this information. Take a look at the ` __FILE__ constant.
So you can take this
__FILE__variable and execute thebasename()function on it to get the file name. Thebasename()function returns the trailing name component of a path. Then you simply do a switch case to match the desired value –Your additional CSS rules can sit within those separate files.
Alternatively, if you don’t want to split your css into multiple files, you can echo those specific rules into your page’s head element like this –
References –
basename()