How-to articles, tricks, and solutions about PHP
There are several ways to sanitize user input in PHP, depending on the type of data and how you plan to use it.
You can use the following HTML code to create a form that allows users to select and upload multiple files.
You can use the array_map() function to trim all strings in an array in PHP.
You can use the scandir() function to get an array of files in a directory, and then check the length of the array.
Here's an example of how you can use the iCalcreator library to create an iCal file and output it for download:
You can use the PHP function readfile() to read the contents of a Word document and then use the appropriate headers to prompt the browser to open or download the file.
To write a file in UTF-8 encoding with PHP, you can use the fopen, fwrite, and fclose functions.
In PHP, you can use the simplexml_load_string function to check if a string is a valid XML without displaying a warning.
To add PHP code to an HTML file, you will need to use PHP tags.
In PHP, you can use the output control functions to capture the output of a PHP script into a variable.
To compare two DateTime objects in PHP 5.2.8, you can use the DateTime::diff() method, which returns a DateInterval object representing the difference between the two dates.
There are several ways to count unique visitors to a website using PHP, but one common method is to use cookies.
In PHP, you can create a copy of an object using the clone keyword.
To display a MySQL error in PHP for a long query that depends on user input, you can use the mysqli_error() function.
To generate a custom menu/sub-menu system using wp_get_nav_menu_items in WordPress, you can follow these steps:
To get a thumbnail image for a YouTube video in PHP, you can use the file_get_contentsfunction to make a GET request to the videos.list method of the YouTube Data API.
Here's an example of how you can implement Long Polling in PHP:
To install Composer on a shared hosting, you can use the following steps:
In PHP, you can use the unserialize function to unserialize a serialized string.
To print all the POST results when a form is submitted with PHP, you can use the print_r($_POST) function.
In PHP, you can use the rmdir() function to remove a directory, and the unlink() function to remove a file.
To remove the last comma from a string in PHP, you can use the rtrim function.
To return a proper success/error message for jQuery.ajax() using PHP, you can do the following:
To see the actual XML generated by the PHP SOAP Client class, you can use the __getLastRequest() method.
You can use the Log facade to write to the console from a Laravel controller.