How-to articles, tricks, and solutions about PHP

json_decode to custom class

In PHP, you can use the json_decode() function to convert a JSON string into a PHP object or array.

Remove control characters from PHP string

In PHP, you can use the preg_replace function to remove control characters from a string.

Why can't PHP create a directory with 777 permissions?

PHP's mkdir() function, which is used to create a new directory, defaults to using the server's current umask setting when determining the permissions of the newly created directory.

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.

How to check if a row exist in the database using PDO?

You can use the rowCount() method of the PDOStatement object to check if a row exists in the database using PDO.

How to pass php variable's value to jquery

You can pass a PHP variable's value to jQuery by using the PHP variable in a JavaScript script, and then accessing it with jQuery.

XML Parse Error - Extra content at the end of the document

This error message typically occurs when there is additional content or characters after the closing root element in an XML document.

How to output the response HTML data by a jQuery AJAX request?

In a jQuery AJAX request, you can output the response HTML data using the .html() method.

configure: error: Please reinstall the libzip distribution

This error message is indicating that there is a problem with the libzip library that is preventing a program from being configured.

Remove all elements from array that do not start with a certain string

You can use the array_filter() function in PHP to remove all elements from an array that do not start with a certain string.

How can I employ "if exists" for creating or dropping an index in MySQL?

In MySQL, you can use the "IF EXISTS" clause when creating or dropping an index to prevent an error from occurring if the index does not exist.

Find last iteration of foreach loop in laravel blade

In Laravel Blade, you can use the @forelse loop to check if the last iteration of a loop has been reached.

Can't use function return value in write context?

In PHP, this error message typically occurs when a function or method that is expected to return a value is being used in a context where a value cannot be written.

Laravel 5 getting ID from URL

In Laravel 5, you can get the ID from the URL by using the $request object or by defining a route parameter in the web.php file.

Try/Catch block in PHP not catching Exception

There could be several reasons why a try/catch block in PHP is not catching an exception.

Get max_execution_time in PHP script

You can use the ini_get() function in PHP to get the value of max_execution_time.

How can I force PHP to use strings for array keys?

In PHP, array keys are typically automatically cast to integers if they are numeric, and to strings if they are not.

PHPExcel Column Loop

To loop through columns in PHPExcel, you can use the following code snippet as an example:

How to delete multiple records using Laravel Eloquent

You can use the destroy() method in Laravel Eloquent to delete multiple records.

How to set for specific directory open_basedir

You can set the open_basedir configuration option in the PHP configuration file (php.ini) to specify a specific directory for the open_basedir setting.

Add class="active" to active page using PHP

You can add the "active" class to the active page using PHP by comparing the current URL to the URL of the page you want to mark as active.

Is there a PHP Sandbox, something like JSFiddle is to JS?

Yes, there are several PHP sandbox options available online.

Can a class extend both a class and implement an Interface

Yes, a class in PHP can extend another class and implement one or more interfaces at the same time.