How-to articles, tricks, and solutions about PHP

PHP & localStorage

PHP is a programming language that is often used to build web applications.

Enable PHP Apache2

To enable PHP for Apache2 on Ubuntu, follow these steps:

Function to return only alpha-numeric characters from string?

To return only alpha-numeric characters from a string in PHP, you can use the preg_replace function with a regular expression pattern that matches any non-alphanumeric character.

How can I replace the deprecated set_magic_quotes_runtime in php?

The set_magic_quotes_runtime function has been deprecated since PHP 5.3 and removed in PHP 7.0.

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 Validate on Max File Size in Laravel?

To validate a file size in Laravel, you can use the size rule in your request validation.

Laravel: getting a single value from a MySQL query

To get a single value from a MySQL query in Laravel, you can use the value method on a query builder instance.

How to check if $_GET is empty?

You can check if the $_GET array is empty by using the empty() function.

Convert multidimensional array into single array

To convert a multidimensional array into a single array in PHP, you can use the array_merge() function.

How to work on UAC when installing XAMPP

To work with User Account Control (UAC) when installing XAMPP, you can try the following steps:

PHP ini file_get_contents external url

To use the file_get_contents function to retrieve the contents of an external URL in PHP, you will first need to ensure that the allow_url_fopen directive is enabled in your php.ini file.

How to store file name in database, with other info while uploading image to server using PHP?

To store the file name in a database along with other information while uploading an image to a server using PHP, you can follow these steps:

What is the difference between the | and || or operators?

In PHP, the "|" and "||" operators are both bitwise and logical operators.

PHP __get and __set magic methods

The __get and __set magic methods in PHP are used to intercept calls to get or set the value of inaccessible properties of an object.

Codeigniter's `where` and `or_where`

In CodeIgniter, the where method on the database class is used to add a WHERE clause to your query.

How to minify php page html output?

To minify HTML output in PHP, you can use the following steps:

Export MySQL database using PHP

To export a MySQL database using PHP, you can use the mysqldump command-line utility or the mysqli extension.

How to get an array of specific "key" in multidimensional array without looping

You can use the array_column function to get an array of specific keys from a multidimensional array.

Setting POST variable without using form

To set the value of a POST variable in PHP, you can use the following code:

How to get page content using cURL?

To get the content of a webpage using cURL, you can use the following command:

How to set and get Cookie in laravel

To set a cookie in Laravel, you can use the Cookie facade.

Save PHP array to MySQL?

To save a PHP array to a MySQL database, you can use the serialize() function to convert the array into a string, and then use an INSERT or UPDATE statement to save the string into a TEXT or LONGTEXT field in the database.

How to install all required PHP extensions for Laravel?

To install all of the required PHP extensions for Laravel, you will need to install the following PHP extensions on your server:

Calculate age based on date of birth

Here is some sample PHP code that calculates a person's age based on their date of birth: