How-to articles, tricks, and solutions about PHP

proper way to logout from a session in PHP

To properly log out of a session in PHP, you can use the session_destroy() function.

Redirect with CodeIgniter

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

Redirecting to authentication dialog - "An error occurred. Please try again later"

This message typically indicates that there is an issue with the authentication process.

Reference — What does this symbol mean in PHP?

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

ReflectionException: Class ClassName does not exist - Laravel

This error message indicates that Laravel is trying to use a class that it can't find.

Refresh a page using PHP

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

relative path in require_once doesn't work

The require_once function in PHP is used to include a specific PHP file in another file, but it will only include the file once to prevent multiple declarations.

reliable user browser detection with php

There are several ways to detect a user's browser using PHP.

Reloading .env variables without restarting server (Laravel 5, shared hosting)

In Laravel 5, you can use the php artisan config:cache command to compile all of your configuration into a single file, which will be loaded quickly by the framework.

Remote file size without downloading file

In PHP, you can use the get_headers() function to retrieve the headers of a remote file.

Remove a child with a specific attribute, in SimpleXML for PHP

You can remove a child element with a specific attribute in SimpleXML for PHP using the xpath() function.

Remove all elements from array that do not start with a certain string

You can use the array_filter() function in PHP to remove all elements from an array that do not start with a certain string.

Remove all non-numeric characters from a string; [^0-9] doesn't match as expected

You can use the preg_replace function in PHP to remove all non-numeric characters from a string.

Remove control characters from PHP string

In PHP, you can use the preg_replace function to remove control characters from a string.

Remove excess whitespace from within a string

To remove excess whitespace from within a string in PHP, you can use the preg_replace() function with a regular expression that matches any sequence of one or more whitespace characters.

Remove new lines from string and replace with one empty space

To remove new lines from a string and replace them with a single empty space in PHP, you can use the str_replace function.

Remove portion of a string after a certain character

There are several ways you can remove a portion of a string after a certain character in PHP.

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.

Request string without GET arguments

In PHP, you can use the $_SERVER['REQUEST_URI'] variable to get the request string without GET arguments.

Resetting MySQL Root Password with XAMPP on Localhost

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

Resolving Memory Limit Exceeded

This error message means that your PHP script is trying to use more memory than what is allowed by your PHP configuration.

Reverse order of foreach list items

To reverse the order of the items in a list when using a foreach loop in PHP, you can simply reverse the array using the array_reverse function before the loop.

Run PHP Task Asynchronously

To run a PHP task asynchronously, you can use the pcntl_fork() function to create a new process that runs the task in parallel with the main script.

Run process with realtime output in PHP

In PHP, you can use the proc_open function to run a process and read its output in real-time.