How-to articles, tricks, and solutions about PHP

Getting data posted in between two dates

To get data posted between two dates in PHP, you can use a SQL query with a WHERE clause and the BETWEEN operator.

Getting the names of all files in a directory with PHP

In PHP, you can use the scandir() function to get the names of all files in a directory.

Getting title and meta tags from external website

In PHP, you can use the file_get_contents() function to retrieve the HTML code of a website, and then use regular expressions or a DOM parsing library to extract the title and meta tags.

Given a Unix timestamp, how to get beginning and end of that day?

You can use the strtotime() function in PHP to convert a Unix timestamp to the beginning and end of that day.

Group array by subarray values

In PHP, you can group an array of arrays (subarrays) by the value of a specific key in each subarray using the array_reduce() function.

Guzzle 6: no more json() method for responses

In Guzzle 6, the json() method for parsing JSON responses has been removed.

Headers and client library minor version mismatch

If you are seeing this error message in PHP, it may be caused by a mismatch between the version of the PHP client library that you are using and the version of the API that it is trying to access.

How are \r \t and \n different from one another?

The characters "\r" (carriage return), "\t" (tab), and "\n" (newline) are all special characters used in strings in the PHP programming language.

How can I check if an array element exists?

In PHP, you can use the "in_array" function to check if an element exists in an array.

How can I count the numbers of rows that a MySQL query returned?

You can use the mysqli_num_rows() function to count the number of rows that a MySQL query returned in PHP.

How can I detect if the user is on localhost in PHP?

You can use the $_SERVER['HTTP_HOST'] variable to detect if the user is on localhost in PHP.

How can I disable notices and warnings in PHP within the .htaccess file?

You can disable notices and warnings in PHP by adding the following line to your .htaccess file:

How can I display the users profile pic using the facebook graph api?

To display a user's profile picture using the Facebook Graph API in PHP, you can make a GET request to the /{user-id}/picture endpoint.

How can I employ "if exists" for creating or dropping an index in MySQL?

In MySQL, you can use the "IF EXISTS" clause when creating or dropping an index to prevent an error from occurring if the index does not exist.

How can I enable the MySQLi extension in PHP 7?

To enable the MySQLi extension in PHP 7, you need to follow these steps.

How can I find the version of php that is running on a distinct domain name?

There are a few ways to find out the version of PHP running on a specific domain name.

How can I force PHP to use strings for array keys?

In PHP, array keys are typically automatically cast to integers if they are numeric, and to strings if they are not.

How can I get the MAC and the IP address of a connected client in PHP?

You can use the $_SERVER['REMOTE_ADDR'] variable in PHP to get the IP address of a connected client.

How can I handle the warning of file_get_contents() function in PHP?

The file_get_contents() function in PHP is used to read a file and return its contents as a string.

How can I prevent SQL injection in PHP?

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

How can I print all the values of an array?

In PHP, you can use a foreach loop to iterate through an array and print each value.

How can I properly URL encode a string in PHP?

To URL encode a string in PHP, you can use the urlencode function.

How Can I Remove “public/index.php” in the URL Generated Laravel?

To remove "public/index.php" from the URL in a Laravel application, you can use the built-in PHP web server or set up a web server with Apache or Nginx.

How can I remove part of a string in PHP?

There are several ways to remove a portion of a string in PHP.

How can I replace the deprecated set_magic_quotes_runtime in php?

The set_magic_quotes_runtime function has been deprecated since PHP 5.3 and removed in PHP 7.0.