Category: PHP

Converting string to date in PHP

Converting strings to dates in PHP requires the use of two functions. strtotime function converts the string to an epoch timestamp. date function converts the timestamp to the desirable date…

Type casting in PHP

PHP does not support explicit type definition in variable declaration. For example, you CANNOT declare a variable as follows: In PHP, a variable’s type is determined by the context in…

How to encrypt a string in PHP

The following code encrypts a string. crypt() function encrypts the string. The last line prints the encrypted string. There is no such function called decrypt(). This is because crypt uses…

PHP Unit Testing with SimpleTest

What is Unit Testing Most developers agree that testing is important but few test their code. Even fever do it methodically. Many developers do not realize that there is a…

PHP: How to convert XML to JSON

Converting XML to JSON is very easy in PHP. See the following code. line 1: open an empty file to write JSON line 2: load xml file line 3: convert…