Categories
PHP

Get Time of day, UTC offset, and DST

The gettimeofday() function executes the underlying gettimeofday(2) system call, it returns the current time (expressed as seconds and microseconds since the Epoch), time zone, and daylight saving time correction information.

Categories
PHP

Converting a Timestamp to Date and Time

In this tutorial, you learn how to get a local date and time with getdate() function, convert a timestamp into date and time with getdate() and date() functions, and convert a date and time into a timestamp with strtotime and mktime functions.

Categories
PHP

Validating a Date

Learn how to validate a date with the help of checkdate() function.

Categories
PHP

Formatting Date and Time

In this tutorial, we’ll discuss the date(), gmdate() and idate() functions. We’ll use these functions to convert a timestamp to readable date and time format, to change the format of a date or time, and to format the current date and time.

Categories
PHP

Generating a Timestamp

The tutorial teaches you various techniques to generate a Unix timestamp for the current or a specific DateTime by using time(), microtime(), mktime(), gmmktime() and strtotime() functions.

Categories
PHP

Data Validation with Regular Expressions

In this tutorial, you’ll see how regular expressions work, we use some of the data validation tasks to demonstrate how we can use regular expressions to validate usernames, phone numbers, and postal codes.

Categories
PHP

Word Boundaries in Regular Expression

How to mark word boundaries to “match a specific word only” using a regular expression.

Categories
PHP

Handling Errors in Regular Expressions

The regular expression functions in PHP do not throw exceptions, so if there is an error in the regular expression, what will you do? To handle regular expressions errors, PHP offers two functions : preg_last_error() and preg_last_error_msg().

Categories
PHP

Escaping special characters in regular expressions

The :.\+*?[^]$(){}=!<>|:-# letters are special characters that make regular expressions work. If you want to match one of these characters you need to write a backslash in front of that character in the pattern. For example, if you want to match a “+” character, you write “\+” in the pattern. You can escape special characters manually by placing a backslash in front of each character you want to match, or you can the use preg_quote() function to escape special characters automatically. In this tutorial, you’ll also learn a technique that helps you to avoid escaping special characters.

Categories
PHP

Regular expression to find in an array and to split a string

How to use preg_split() function to split strings based on regular expressions and how to use preg_grep() function to search through an entire array of strings looking for text that matches a regular expression.