How-to articles, tricks, and solutions about PHP

Reference — What does this symbol mean in PHP?

In PHP, $this is a special variable that refers to the current object.

Convert flat array to a delimited string to be saved in the database

You can use the implode() function to convert an array to a delimited string in PHP.

Get URL query string parameters

To get the query string parameters in PHP, you can use the $_GET superglobal array.

Remove trailing delimiting character from a delimited string

To remove the trailing delimiter from a delimited string in PHP, you can use the rtrim function.

Refresh a page using PHP

You can refresh a page using PHP using the header function.

How do I get a YouTube video thumbnail from the YouTube API?

To get a thumbnail image for a YouTube video in PHP, you can use the file_get_contentsfunction to make a GET request to the videos.list method of the YouTube Data API.

How can I prevent SQL injection in PHP?

There are several ways to prevent SQL injection attacks in PHP.

How to Use the expm1() Function in PHP

In this snippet, you will find comprehensive and helpful guidelines on how to use the expm1() function in PHP.

How to Use "or" in Switch Case in PHP

In this snippet, you will figure out how to use the "or" operator in a switch case in PHP. Read on, check out and try the examples.

How to Separate Odd and Even Elements from an Array Without Using a Loop in PHP

Here, we provide a snippet, explaining how to separate odd and even elements from an array without using a loop in PHP. Read on and check out the examples.

How to Use bcrypt to Hash Passwords in PHP

There is a password hashing technique, used for building the security of passwords. It is called bcrypt. Here, you will learn how to use it in PHP.

How to Turn Off Notices in PHP

In PHP, notices are known as “soft errors”. However, at times developers want to turn them off. Here, we will show you how to act to turn off PHP notices.

How to Remove and Reindex an Array Element in PHP

Sometimes, in the course of working with PHP, it is necessary to remove and reindex an array element. Here, you will find simple and helpful methods to do that.

How to Deal With Undefined Offset Error in PHP

Here is a snippet that will help you to deal with a common PHP undefined offset error. Here, you will find three methods that help to avoid such an error.

How to Use the AND Operator in PHP

Logical operators are supported by PHP. Let’s explore how to use one of the most commonly used logical operators in PHP: AND.

How to Count All the Array Elements with PHP

While working with arrays, it is commonly necessary to count all its elements. This snippet will discover two helpful functions that will help you do that.

How to Use the mhash_keygen_s2k() Function in PHP

The aim of this snippet is to represent to you the PHP mhash_keygen_s2k() function. Read on and check out the example for better understanding.

How to Read Request Headers in PHP

The given snippet explores how to read request readers in PHP. Read it and learn the most helpful methods of reading any request headers in PHP.

How to Replace a Word Inside a PHP String

Sometimes, it is necessary to replace a given word inside a string in PHP. Here, we will consider three helpful functions that help to carry out the task.

How to Use the func_get_arg() Function in PHP

In this snippet, we will demonstrate to you how to use one of the common PHP functions: func_get_arg().

How to Log Errors and Warnings in a File with PHP

With the help of this snippet, you can learn how to log errors and warnings in a file in PHP. Go ahead and check out the examples.

How to Measure Script Execution Time in PHP

In this snippet, we demonstrate the simplest way of measuring the execution time of a string in PHP. Read on and check out the examples.

How to Use Callbacks in PHP

Here, we will demonstrate how to use standard callbacks, static class method callbacks, object method callbacks, as well as closure callbacks in PHP.

How to Count the Pages in a PDF File with PHP

PHP provides a range of extensions and functions for getting the number of pages in a PDF document. Let’s check out the most efficient ones, here.

How to Generate Static Classes in PHP

This snippet will assist you in working with classes in PHP. Learn how to generate static classes with the help of our guidelines.