PHP Archives - Page 4 of 6 - Ian Carnaghan

How to add months to a given date using PHP

By using the PHP functions date and strtotime this can be accomplished. Example  $date = '2010-03-22';   $new_date = date('Y-m-d',strtotime('+4 months',strtotime($date)));   echo $new_date; //Displays...

Mar 22 · 27 sec read >

How to check if an array contains a empty element or value

Use the following code example $array = array('a','b',''); //The array to check for empty values echo (in_array('  ', $array))...

Mar 22 · 10 sec read >

What is the difference between public, private and protected keywords?

Public – Are variables that are visible to all classes Private -Are variables that are visible only to the class they...

Mar 22 · 9 sec read >

How to check for empty values within a array using PHP

If you have an array called $array with the below values Array ( => 1299016800 => => )...

Mar 22 · 25 sec read >

How to transform a month number to the relevant month name using PHP

This can be obtained by combining the date function with the mktime function For example if I want to get Jan from the number 1 which represents...

Mar 22 · 23 sec read >

How to raise the PHP memory limit, upload limit, or script execution time limit within the .htaccess file

Open your .htaccess file and add the line below to it php_value memory_limit 40M This will increase the PHP memory limit, if the altering...

Mar 22 · 6 sec read >

How to auto submit a Sitemap to Google using PHP

This can be done via a ping service from Google Webmaster Tools Add the following PHP function  function submitSitemap($site)...

Mar 22 · 35 sec read >

How to detect the data type of a PHP variable

The data type of a PHP variable can be detected by using the built-in PHP functiongettype() (PHP 4, PHP 5) Example: $var ="This is a sentence" echo $var; //This...

Mar 22 · 10 sec read >

Calculating the difference in days between 2 dates in PHP

$startDate = '1999-03-12';   $endDate = '2011-03-12';     $days = (strtotime($endDate)-strtotime($startDate)) / (60 * 60 * 24);  ...

Mar 22 · 20 sec read >