How-to articles, tricks, and solutions about PHP

Laravel csrf token mismatch for ajax POST Request

The csrf_token error you are encountering occurs when you are making a POST request to your Laravel application and you have not included a valid CSRF token in the request.

Detecting request type in PHP (GET, POST, PUT or DELETE)

In PHP, you can use the $_SERVER['REQUEST_METHOD'] superglobal to detect the request type.

How to convert an image to Base64 encoding

To convert an image to base64 encoding in PHP, you can use the base64_encode() function

PHP append one array to another (not array_push or +)

To append one array to another in PHP, you can use the array_merge function.

String comparison using '==' or '===' vs. 'strcmp()'

In PHP, you can use either the == or === operator to compare two strings.

Warning: A non-numeric value encountered

This warning message is indicating that a non-numeric value has been encountered in a place where a number is expected.

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.

What is the difference between public, private, and protected?

In PHP, public, private, and protected are access modifiers that control the visibility of class properties and methods.

How to enable PHP short tags?

PHP short tags are a shortened version of the standard PHP opening tag.

Laravel 5 – Clear Cache in Shared Hosting Server

To clear the cache in Laravel 5, you can use the php artisan cache:clear command.

Enumerations on PHP

In PHP, an enumeration is a value that is set to a fixed set of values.

How can I sanitize user input with PHP?

There are several ways to sanitize user input in PHP, depending on the type of data and how you plan to use it.

PHP 7: Missing VCRUNTIME140.dll

It looks like you are encountering an error related to a missing VCRUNTIME140.dll file when using PHP 7.

Passing an array to a query using a WHERE clause

To pass an array to a WHERE clause in PHP, you can use the implode function to join the array elements with a comma separator and use them in your WHERE clause.

What is stdClass in PHP?

In PHP, stdClass is a predefined class, which is part of the PHP standard library

Difference between require, include, require_once and include_once?

In PHP, require and include are two statements that are used to include a file in a PHP script.

MySQL query to get column names?

To get the column names of a table in MySQL, you can use the SHOW COLUMNS FROM command.

How to send a GET request from PHP?

To send a GET request from PHP, you can use the file_get_contents function or the cURL extension.

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

This error message indicates that the client was unable to connect to the MySQL server.

List all files in one directory PHP

To list all files in a directory using PHP, you can use the glob() function.

Could not open input file: artisan

It looks like you are trying to run the artisan command but are getting an error saying that the input file could not be found.

How to get time difference in minutes in PHP

To get the time difference in minutes between two dates in PHP, you can use the DateTime class and the diff() method.

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.

What does the PHP error message "Notice: Use of undefined constant" mean?

The PHP error "Notice: Use of undefined constant" means that you are trying to use a constant that has not been defined yet.

mysql_fetch_array() expects parameter 1 to be resource

It looks like you are trying to use a function from the MySQL extension in PHP, but you are getting an error saying that the first parameter should be a resource.