PHP and MySQL Frequently Asked Questions
- How to write comments in PHP
- How to remove white space from a string in PHP
- How to find number of characters in a string in PHP
- How to find the number of words in a string in PHP
- How to remove HTML special characters from a string in PHP
- How to prepend a string in PHP
- How append a string in PHP
- How to extract substring from a string in PHP
- How to compare two strings in PHP
- How to get current page URL in PHP
- How to create a string by joining the values of an array in PHP
- How to split a string into an array in PHP
- How to combine two strings in PHP
- How to convert a string to lowercase in PHP
- How to convert a string to uppercase in PHP
- How to convert the first letter of a string to uppercase in PHP
- How to convert special HTML entities back to characters in PHP
- How to remove white space from the beginning of a string in PHP
- How to remove white space from the end of a string in PHP
- How to create a new line in PHP
- How to find string length in PHP
- How to check whether a variable is set or not in PHP
- How to check whether a variable is empty in PHP
- How to check whether a variable is null in PHP
- How to reverse a string in PHP
- How to replace the part of a string with another string in PHP
- Counts how many times a substring occurs in a string in PHP
- How to count all elements or values in an array in PHP
- How to print or echo all the values of an array in PHP
- How to display array structure and values in PHP
- How to reverse the order of an array in PHP
- How to check if a key exists in an array in PHP
- How to remove the last element from an array in PHP
- How to remove the first element from an array in PHP
- How to add elements to the beginning of an array in PHP
- How to add elements to the end of an array in PHP
- How to merge two or more arrays into one array in PHP
- How to sort an array values alphabetically in PHP
- How to remove duplicate values from an array in PHP
- How to randomize the order of an array in PHP
- How to compare two array values in PHP
- How to calculate the sum of values in an array in PHP
- How to remove empty values from an array in PHP
- How to populate dropdown list with array values in PHP
- How to get all the keys of an associative array in PHP
- How to get all the values from an associative array in PHP
- How to sort an associative array by key in PHP
- How to sort an associative array by value in PHP
- How to get single value from an array in PHP
- Foreach loop through multidimensional array in PHP
- How to Delete an Element from an Array in PHP
- How to Check If a String Contains a Specific Word in PHP
- How to Get the Current Date and Time in PHP
- How to Make a Redirect in PHP
- How to Strip All Spaces Out of a String in PHP
- How to Get the Current Year using PHP
- How to Convert a Date from yyyy-mm-dd to dd-mm-yyyy Format in PHP
- How to Convert a String to a Number in PHP
- How to Get the First Element of an Array in PHP
- How to Convert a Date to Timestamp in PHP
- How to Add Elements to an Empty Array in PHP
- How to Convert an Integer to a String in PHP
- How to Delete PHP Array Element by Value Not Key
- How to Push Both Key and Value Into an Array in PHP
- How to Refresh a Page Periodically Using PHP
- How to Remove the Last Character from a String in PHP
- How to Return JSON from a PHP Script
- How to get PHP Errors to Display
Use the
ini_set()
FunctionFor security reasons, error display in production environments is disabled by default.
But, if you want to display errors in a PHP file for debugging purposes, you can place these lines of code at the top of your PHP file, as shown in the following example:
However, this doesn't make PHP to show parse errors (such as missing semicolon). The only way to show those errors is to set the
display_errors
directive toOn
inphp.ini
file. By defaultdisplay_errors
set toOff
for production environments.After modifying the php.ini file restart your web server, or php-fpm service if you are using PHP-FPM.
However, if you don't have access to
php.ini
file—for instance, if you're using a shared hosting—then putting the following line in.htaccess
file might also work.Warning: Outputting errors in production environments could be very dangerous. Sensitive information could potentially leak out of your application such as database usernames and passwords or worse. For production environments, logging errors is recommended.