PHP Archives - Page 3 of 6 - Ian Carnaghan

How to remove all white spaces within a string using PHP

There are two functions that could be used namely str_replace and  preg_replace. First, we’ll give an example using str_replace. str_replace is the preferred method since...

Mar 22 · 30 sec read >

How to alternate between 2 colors using PHP

This could come in handy if you have a table with multiple rows and if you wish to alternate...

Mar 22 · 27 sec read >

How to convert a MySQL Datetime field to a Unix Timestamp using PHP

In the example you’ll find a handy PHP function that will do the conversion. <?php   $DATETIME = '2010-04-22...

Mar 22 · 28 sec read >

How to get the current UNIX timestamp using PHP

UNIX TIMESTAMP: Is the time measured in seconds since the start of the Unix epoch “1 January 1970” Use the PHP...

Mar 22 · 9 sec read >

How to get the first element of an array using PHP

If you have the array $array = array('a','b','c','d'); you will need to get the value a from the array Answer: Use...

Mar 22 · 13 sec read >

How to change the Return-path email address using the PHPMailer class

Fill the $Sender property with the email address you wish to have as the Return-path  E.g. $mail->Sender="[email protected]"; This property can be found...

Mar 22 · 14 sec read >

Getting PHP Fatal error: Can’t use function return value in write context

Make sure that you did not include a function within the empty PHP function. eg if(empty(getUsers())){}

Mar 22 · 3 sec read >

How to validate a date format using PHP

To check whether the date entered is in the correct format NOTE: We will use the following date format...

Mar 22 · 15 sec read >

How to compare two dates using PHP

First we need to convert the two dates to UNIX Timestamps using the PHP function strtotime Then we can compare the two...

Mar 22 · 15 sec read >