How-to articles, tricks, and solutions about PHP

PHP - Copy image to my server direct from URL

To copy an image from a URL and save it to your server using PHP, you can use the following function:

curl error 18 - transfer closed with outstanding read data remaining

Error 18 means that the transfer was closed with outstanding read data remaining.

PHP Error: Function name must be a string

This error typically occurs when you are trying to call a function, but you are not passing a string as the name of the function.

How to use sha256 in php5.3.0

In PHP 5.3.0, you can use the hash function to create a SHA-256 hash.

Why is textarea filled with mysterious white spaces?

There could be a number of reasons why a textarea element in a PHP webpage might be filled with mysterious white spaces.

Laravel - Session store not set on request

It sounds like you are trying to use the Laravel session, but it is not available in the current request.

Where does PHP's error log reside in XAMPP?

In XAMPP, the error log for PHP is typically located at {xampp-install-directory}/php/logs/php_error_log.

Troubleshooting "The use statement with non-compound name"

The error "The use statement with non-compound name" usually indicates that you are trying to use a namespace in a use statement, but you did not provide a compound name.

PHP using Gettext inside <<<EOF string

It is possible to use the gettext function inside a heredoc string in PHP.

Trying to get Laravel 5 email to work

To get Laravel 5's email functionality to work, you will need to configure your SMTP settings in the .env file, located in the root directory of your Laravel project.

Truncate string in Laravel blade templates

To truncate a string in a Laravel blade template, you can use the str_limit function.

Calling other function in the same controller?

In PHP, you can call a function within the same controller by simply calling the function name followed by parentheses.

Where is localhost folder located in Mac or Mac OS X?

On Mac and Mac OS X, the localhost folder is located at:

phpMyAdmin mbstring error

It looks like you are encountering an error with the mbstring extension in PHP when using phpMyAdmin.

How to remove extension from string (only real extension!)

To remove the extension from a string in PHP, you can use the pathinfo() function and the basename() function.

How to add property to object in PHP >= 5.3 strict mode without generating error

In PHP >= 5.3, you can use the Object::$strictProperties property to enable or disable strict property checking for an object.

Best way to do a PHP switch with multiple values per case?

To get specific attributes from a Laravel Collection, you can use the pluck method.

Get only specific attributes with from Laravel Collection

To get specific attributes from a Laravel Collection, you can use the pluck method.

Measuring the distance between two coordinates in PHP

To calculate the distance between two coordinates in PHP, you can use the Haversine formula, which is a formula used to calculate the distance between two points on a sphere based on their longitudes and latitudes.

Laravel Migration table already exists, but I want to add new not the older

If you have an existing table in your database that you want to add new columns to using a Laravel migration, you can use the Schema::table method to modify the existing table.

How to to send mail using gmail in Laravel?

To send email using Gmail in Laravel, you can use the built-in Swift Mailer library.

Twig ternary operator, Shorthand if-then-else

In PHP, you can use the ternary operator to perform a shorthand if-then-else statement.

Htaccess: add/remove trailing slash from URL

To add or remove a trailing slash from the end of a URL using an .htaccess file, you can use mod_rewrite to rewrite the URL.

How to include Authorization header in cURL POST HTTP Request in PHP?

To include the Authorization header in a cURL POST request in PHP, you can use the CURLOPT_HTTPHEADER option and pass it an array of headers like this:

Convert column integer values into date expressions

To convert column integer values into date expressions in PHP, you can use the date function.