How-to articles, tricks, and solutions about PHP

PHP string "contains"

To check if a string contains another string in PHP, you can use the strpos() function.

PHP-FPM doesn't write to error log

There are a few things you can try to troubleshoot this issue:

How to add an ORDER BY clause using CodeIgniter's Active Record methods?

To add an ORDER BY clause to a query using CodeIgniter's Active Record class, you can use the order_by() method.

Laravel - Eloquent or Fluent random row

In Laravel's Eloquent ORM, you can use the inRandomOrder method to retrieve a random row from the database.

How to remove line breaks (no characters!) from the string?

There are a few different ways to remove line breaks from a string in PHP. Here are two options.

PHP mkdir: Permission denied problem

The "Permission denied" error message is usually caused by a lack of write permissions for the user that is running the PHP script.

How to Flatten a Multidimensional Array?

You can use array_walk_recursive() function in PHP to flatten a multidimensional array.

How can I select and upload multiple files with HTML and PHP, using HTTP POST?

You can use the following HTML code to create a form that allows users to select and upload multiple files.

Passing multiple variables to another page in url

There are several ways to pass variables from one PHP page to another.

PHP form - on submit stay on same page

To stay on the same page after a form submission in PHP, you can use the following steps.

How to get a substring between two strings in PHP?

You can use the strpos function to find the position of the first occurrence of a substring in a string, and then use the substr function to extract the desired substring.

Displaying the Error Messages in Laravel after being Redirected from controller

In Laravel, you can use the withErrors method to pass error messages to a view after a redirect.

array_push() with key value pair

To add an element to the end of an array with a key-value pair in PHP, you can use the array_push() function.

The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

It is true that the MySQL extension is deprecated, and it is recommended to use either MySQLi or PDO instead.

How do I compare two DateTime objects in PHP 5.2.8?

To compare two DateTime objects in PHP 5.2.8, you can use the DateTime::diff() method, which returns a DateInterval object representing the difference between the two dates.

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.

Check if $_POST exists

To check if the $_POST superglobal variable exists in PHP, you can use the isset() function.

How do I print all POST results when a form is submitted?

To print all the POST results when a form is submitted with PHP, you can use the print_r($_POST) function.

Resetting MySQL Root Password with XAMPP on Localhost

To reset the root password for MySQL on XAMPP, you can follow these steps.

Redirect with CodeIgniter

In CodeIgniter, you can use the redirect() function to redirect the user's browser to a new page.

Array and string offset access syntax with curly braces is deprecated

In PHP, using array and string offset access syntax with curly braces has been deprecated as of PHP 7.4.

CURL ERROR: Recv failure: Connection reset by peer - PHP Curl

This error is usually caused by a network issue, such as a lost connection or a network timeout.

selecting unique values from a column

To select unique values from a column in PHP, you can use the array_unique function.

How to get body of a POST in php?

To get the body of a POST request in PHP, you can use the file_get_contents function and pass it the special php://input stream.

Print array to a file

To print an array to a file in PHP, you can use the file_put_contents() function, which writes a string to a file.