How-to articles, tricks, and solutions about PHP

How to get the first day of the current year?

In PHP, you can use the mktime function to get the Unix timestamp of the first day of the current year, then use the date function to format it as a date string.

How to pass an array via $_GET in php?

In PHP, arrays can be passed in the URL using the $_GET superglobal variable, but they need to be encoded first using the http_build_query() function.

Symfony error The class XXX was not found in the chain configured namespaces XXX

This error message is indicating that the Symfony framework is unable to find a specific class within the namespaces that have been configured.

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.

Get All simple product from a Configurable Product in Magento Product View

In Magento, a configurable product is made up of multiple simple products, each with different options such as size or color.

PHP How to add to end of array?

In PHP, you can add an element to the end of an array using the array_push() function.

get array of rows with mysqli result

You can use the mysqli_fetch_assoc() function to retrieve an associative array of a single row from a result set, and use a loop to iterate through the result set and store each row in an array.

Generating cryptographically secure tokens

In PHP, you can use the built-in function random_bytes() to generate cryptographically secure random bytes, which can then be converted into a token.

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:

FastCGI process exceeded configured activity timeout

FastCGI is a protocol for interfacing interactive programs with a web server.

WordPress Issue: Cannot modify header information - headers already sent by

This error message appears when a PHP script is trying to modify the headers of an HTTP response after the headers have already been sent.

Laravel Carbon: how to change timezone without changing the hour?

In Laravel, you can use the setTimezone method on a Carbon instance to change the timezone without changing the hour.

PHP create PDF invoice

There are several libraries available in PHP that can be used to create PDF invoices, such as TCPDF and FPDF.

How to run my php file from mac terminal?

To run a PHP file from the Mac terminal, you will need to have a web server installed, such as Apache, and PHP should be configured correctly with the server.

where is php.ini on ubuntu?

On Ubuntu, the location of the php.ini file depends on the version of PHP you have installed.

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 handle Undefined Offset in laravel?

In Laravel, an "Undefined offset" error typically occurs when trying to access an array index that does not exist.

Merging cells in Excel by rows and columns together using PHPExcel

To merge cells in Excel using PHPExcel, you can use the mergeCells() method.

php echo if two conditions are true

You can use the if statement in PHP to check if two conditions are true.

PHP_SELF vs PATH_INFO vs SCRIPT_NAME vs REQUEST_URI

PHP_SELF, PATH_INFO, SCRIPT_NAME, and REQUEST_URI are all superglobal variables in PHP that provide information about the current URL being requested.

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.

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.

Multiple excerpt lengths in wordpress

In WordPress, the length of the excerpt (the summary text displayed on the homepage or archive pages) can be controlled by the theme or by a plugin.

Send html form data to sql database via php (using mysqli)

To send HTML form data to a SQL database using PHP, you will need to use the mysqli (MySQL Improved) extension in PHP.

1 2 3 4 5