How-to articles, tricks, and solutions about PHP

How to display string that contains HTML in twig template?

To display a string that contains HTML in a Twig template, you can use the raw filter.

How to display Woocommerce Category image?

To display a category image in WooCommerce, you can use the woocommerce_subcategory_thumbnail hook in your theme's functions.php file.

How to display woocommerce sale price or regular price if there is no sale price

In WooCommerce, you can display the sale price or regular price of a product using the following code snippet:

How to do single sign-on with PHP?

Single sign-on (SSO) allows users to authenticate once and gain access to multiple applications without having to re-enter their credentials.

How to Download a File in PHP

PHP is a popular general-purpose scripting language. It provides files to the user by forcing them to download. Know how to download a file in PHP correctly.

How to enable cURL in PHP / XAMPP

To enable cURL in PHP, you need to make sure that the cURL extension is enabled in your PHP configuration.

How to enable PHP short tags?

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

How to Encrypt and Decrypt a String in PHP

On this page, you can find comprehensive information about encrypting and decrypting a string in PHP. Learn how to do it with the functions of openssl.

How to escape strings in SQL Server using PHP?

In PHP, you can use the sqlsrv_real_escape_string() function to escape strings in SQL Server.

How to Expire a PHP Session

On this page, we are going to provide you with a step-by-step guide on how to expire a PHP session after 30 minutes.

How to fake $_SERVER['REMOTE_ADDR'] variable?

It is generally not recommended to fake the $_SERVER['REMOTE_ADDR'] variable, as it can lead to security vulnerabilities and potential abuse of the system.

How to find array / dictionary value using key?

In PHP, you can use the $array[$key] syntax to get the value stored at a particular key in an array.

How to find average from array in php?

You can use the array_sum function to get the sum of all the values in an array, and then divide that sum by the number of elements in the array to get the average.

How to find day of week in php in a specific timezone

To find the day of the week in PHP in a specific timezone, you can use the date function and specify the timezone using the date_default_timezone_set function.

How to find my php-fpm.sock?

To find your PHP-FPM socket file, you will need to first determine the location of your PHP installation.

How to Find the foreach Index with PHP

Here is a short tutorial where you can find three helpful methods allowing to find the foreach index with the help of PHP.

How to fix 'Creating default object from empty value' warning in PHP?

This error typically occurs when a variable is accessed as an object, but it has not been initialized or set to an object.

How to fix "set SameSite cookie to none" warning?

To fix the "set SameSite cookie to none" warning in PHP, you will need to specify the SameSite attribute when you set the cookie.

How to Fix the "Invalid Argument Supplied for Foreach()" PHP Error

The "invalid argument supplied for foreach()" is considered a common PHP error. With the help of this tutorial, you will figure out how to resolve it.

How to Fix the Uncaught Error "Cannot Use Object of Type stdClass as an Array"

This short tutorial is dedicated to a common PHP issue "cannot use object of Type stdClass as an array". Read on to find the most accurate solutions.

How to fix Warning Illegal string offset in PHP

The "Illegal string offset" warning in PHP occurs when you try to access an offset of a string variable as if it were an array.

How to Flatten a Multidimensional Array?

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

How to Format Laravel Blade Code in Visual Studio Code?

You can use the Laravel Blade Snippets extension for Visual Studio Code to format Blade code in your Laravel projects.

How to Generate a Default Function Parameter in PHP

In this snippet, we will have a look at the process of generating and using default function parameter in PHP.

How to Generate a Random String with PHP

This tutorial includes several methods of generating a unique, random, alpha-numeric string with PHP. Follow the examples below, it will be easily done.