Monday, July 29, 2013

How to know if the browser is IE in PHP

Hi. This is a small code to check the browser is Internet explorer or not using the PHP.
if(preg_match('/(?i)msie [1-8]/', $_SERVER['HTTP_USER_AGENT']))
   // The browser is IE 
   // write your code here
   // The browser is other than IE
   // write your code here

If you are executing the above code in Internet explorer browser then if condition will execute. and if you are executing the code in other than Internet explorer then else condition will be executed.

Thank you

Friday, July 12, 2013

How to display the previous days date using PHP

Hi to every one. Today am going to give a small code to show the previous day date using the PHP. Just copy and paste the below code into your editor and change the static number to your number.
date('Y/m/d', strtotime('-N days',strtotime(date('Y/m/d'))));

date('Y/m/d') will gives current date.
strtotime(date('Y/m/d')) will convert the current date to UNIX Timestamp.
Here '-' represents the previous days to show. 
Here 'N' is the number to show 'Nth' days ago date from the current date.
'-N days' will gives the previous 'Nth' day date.
strtotime('-N days',strtotime(date('Y/m/d')) will gives the UNIX Timestamp string of previous 'Nth' day date.
date('Y/m/d', strtotime('-N days',strtotime(date('Y/m/d')))) will display the UNIX Timestamp to date format of YYYY/MM/DD.

For example:
Assume that current date is 2013/07/12. and if we want to display 7 days ago date then write the following code.
date('Y/m/d', strtotime('-7 days',strtotime(date('Y/m/d'))));
It will show the last 7 days ago date in the format of 2013/07/05.