How-to articles, tricks, and solutions about PHP
To get latitude and longitude automatically using PHP, you can use an API (Application Programming Interface) such as Google Maps API, OpenCage Geocoding API, or GeoCode.io API.
You can use the following code snippet to add "http://" to the beginning of a URL if it doesn't already exist:
In PHP, you can use the scandir() function to list the files and directories in a directory.
This error message is indicating that the PHP script is trying to open a file using the fopen() function, but the script does not have the necessary permissions to access the file.
In PHP, you can use the built-in function strtotime() to convert a date string to a Unix timestamp, which is the number of seconds since the Unix epoch (January 1, 1970).
In PHP, you can read a specific line from a file using the file() function, which reads the entire file into an array, with each line of the file as an element in the array.
This error message is indicating that there is a problem with the syntax of the code, specifically a parse error, and that it was unexpected to find the token "T_PAAMAYIM_NEKUDOTAYIM" in that particular place in the code.
In Symfony2, you can use the $this->get('kernel')->getRootDir() method inside a controller to get the server path to the web directory.
To automatically start a download in PHP, you can use the header() function to send the appropriate headers to the browser indicating that a file download should begin.
The location of the curl installation depends on the operating system and the method used to install it.
To return JSON from a PHP script to a jQuery AJAX call, you can use the json_encode() function in PHP to convert an array or object into a JSON string.
You can use the strpos() function in PHP to search for a specific string within another string.
In PHP, the maximum size of the parameters in a GET request is determined by the server's configuration.
In PHP, you can post a hidden value by including it in a hidden input field within a HTML form.
The "Illegal string offset" warning in PHP occurs when you try to access an offset of a string variable as if it were an array.
You can use the array_map() function to trim all strings in an array in PHP.
In PHP 7, type hinting can be used to specify the expected data type of a function or method parameter.
You can use the array_sum function to get the sum of all the values in an array, and then divide that sum by the number of elements in the array to get the average.
To display a user's profile picture using the Facebook Graph API in PHP, you can make a GET request to the /{user-id}/picture endpoint.
You can use the scandir() function to get an array of files in a directory, and then check the length of the array.
You can use the latest method on a query builder instance to get the last N entries from the database.
In Drupal, you can use the url() function to get the full URL of a page.
Here is an example of a basic XSS filtering function in PHP:
To send an emoji using the Telegram Bot API in PHP, you can use the sendMessage method and include the emoji in the text of the message.