How-to articles, tricks, and solutions about PHP

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes)

This is a PHP error message that indicates your script is trying to use more memory than the amount specified in the PHP configuration.

How to call a php script/function on a html button click?

To call a PHP script or function on a HTML button click, you can use JavaScript to send an HTTP request to the server when the button is clicked.

How to disable registration new users in Laravel

To disable registration of new users in Laravel, you can remove the registration routes from the web.php file in the routes folder.

PHP: How to handle <![CDATA[ with SimpleXMLElement?

You can use the addCData() method of the SimpleXMLElement class to add a CDATA section to an XML element.

Laravel back button

In Laravel, you can use the back function to redirect the user to their previous page.

Eloquent model mass update

To update multiple records in the Eloquent ORM (Object-Relational Mapping) in Laravel, you can use the update() method on the query builder or on a model instance.

PHP new line break in emails

In PHP, you can use the built-in function "nl2br" to convert newline characters to HTML line breaks in emails.

In PHP with PDO, how to check the final SQL parametrized query?

In PHP with PDO, you can use the debugDumpParams() method on a prepared statement object to view the final SQL parametrized query.

PHP UML Generator

There are several UML generators available for PHP, including:

SimpleXml to string

To convert a SimpleXml object to a string in PHP, you can use the asXML() function.

How to "flatten" a multi-dimensional array to simple one in PHP?

In PHP, you can use the "array_reduce" function to flatten a multi-dimensional array.

Generating a random hex color code with PHP

You can use the dechex function in PHP to convert a random number to a hexadecimal value, and then use that value as a color code.

PHP: Check if an array contains all array values from another array

You can use the array_diff function in PHP to compare two arrays and check if the first array contains all of the values from the second array.

How to write a link like <a href="#id"> which link to the same page in PHP?

In PHP, you can use the echo function to output an HTML <a> tag with a "#id" value for the href attribute, which will link to the same page.

Getting the names of all files in a directory with PHP

In PHP, you can use the scandir() function to get the names of all files in a directory.

How to get primary key of table?

To get the primary key of a table in PHP, you can use the SHOW KEYS SQL statement to retrieve information about the keys (including the primary key) of a table.

How to print all information from an HTTP request to the screen, in PHP

In PHP, you can use the $_SERVER superglobal array to access information about the current HTTP request.

Save image from url with curl PHP

To save an image from a URL using PHP and cURL, you can use the following function:

php resize image on upload

To resize an image on upload in PHP, you can use the getimagesize function to determine the dimensions of the image, then use the imagecreatetruecolor function to create a new image with the desired dimensions.

PHP code to get selected text of a combo box

To get the selected text of a combo box (also known as a dropdown menu or select box) in PHP, you can use the following code:

get all the images from a folder in php

To get all the images from a folder in PHP, you can use the glob function.

PHP - Extracting a property from an array of objects

To extract a property from an array of objects in PHP, you can use the array_column function.

How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?

In PHP, you can use the utf8_decode() function to decode a string that contains Unicode escape sequences.

Reverse order of foreach list items

To reverse the order of the items in a list when using a foreach loop in PHP, you can simply reverse the array using the array_reverse function before the loop.