How-to articles, tricks, and solutions about PHP

Twig for loop for arrays with keys

To loop through an array with keys in Twig, you can use the for loop and access the key and value of each element in the array using the loop variable.

Twig ternary operator, Shorthand if-then-else

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

Type hinting in PHP 7 - array of objects

In PHP 7, type hinting can be used to specify the expected data type of a function or method parameter.

unexpected 'use' (T_USE) when trying to use composer

This error message is indicating that there is an unexpected use of the keyword "use" in your code when trying to run Composer.

Unicode character in PHP string

You can use Unicode characters in a PHP string by including the character directly in the string, or by using the \u escape sequence followed by the Unicode code point of the character in hexadecimal.

Unique and temporary file names in PHP?

In PHP, you can use the tempnam() function to generate a unique and temporary file name.

Update PHP to 7.4 macOS Catalina with brew

To update PHP to version 7.4 on macOS Catalina using Homebrew, you can use the following steps:

Upgrading PHP in XAMPP for Windows?

To upgrade PHP in XAMPP for Windows, you will need to follow these steps.

Upgrading PHP on CentOS 6.5 (Final)

Upgrading PHP on CentOS 6.5 can be a bit tricky, since CentOS 6.5 uses an older version of PHP.

Upload DOC or PDF using PHP

To upload a DOC or PDF file using PHP, you will need to use the move_uploaded_file function.

Uploading files with SFTP

To upload files using SFTP (Secure File Transfer Protocol) in PHP, you can use the SSH2 extension, which allows you to connect to an SFTP server and perform various operations such as uploading, downloading, and deleting files.

Use cURL with SNI (Server Name Indication)

Server Name Indication (SNI) is an extension to the Transport Layer Security (TLS) protocol that allows a client to specify the hostname it is trying to connect to at the start of the handshaking process.

Use different PHP version CLI executable for one command

You can use the alias command in your terminal to create a new command that runs a different version of PHP.

Using $this inside a static function fails

Using $this inside a static function is not allowed in PHP because the $this variable is only available within the context of a non-static method.

UTF-8 problems while reading CSV file with fgetcsv

UTF-8 is a character encoding that supports a wide range of characters and is often used for handling multilingual text.

utf-8 special characters not displaying

This issue is likely caused by a mismatch between the character encoding used by the source of the text (e.g.

UTF8 Encoding problem - With good examples

UTF-8 is a character encoding that represents each character in a text document as a unique numerical code.

Verify ImageMagick installation

To verify that ImageMagick is installed, you can use the command-line tool "convert".

WAMP Server ERROR "Forbidden You don't have permission to access /phpmyadmin/ on this server."

It sounds like you are trying to access the PHPMyAdmin interface on your WAMP server and are receiving a "Forbidden" error message.

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.

Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,

This error message is indicating that there is an issue with an entity reference in the HTML code being parsed by the DOMDocument class.

Warning: mysqli_connect(): (HY000/2002): No such file or directory

This error message is indicating that there is a problem connecting to the MySQL server.

Way to get all alphabetic chars in an array in PHP?

You can use the range() function to get all alphabetic characters in an array in PHP.

What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

Long-polling, WebSockets, Server-Sent Events (SSE), and Comet are all techniques used to enable real-time communication between a client (usually a web browser) and a server.

What are the Differences Between "php artisan dump-autoload" and "composer dump-autoload"?

php artisan dump-autoload is a command that is part of the Artisan command-line interface included with Laravel.