How-to articles, tricks, and solutions about PHP

PHP Fatal Error Failed opening required File

A "PHP Fatal Error: Failed opening required file" error usually occurs when a PHP script tries to include a file that does not exist or cannot be accessed.

PHP Fatal error when trying to access phpmyadmin mb_detect_encoding

A PHP Fatal error is a type of error that occurs when the PHP interpreter encounters a serious problem and is unable to continue executing the script.

PHP Fatal error: Call to undefined function curl_init()

This error message indicates that the PHP script is trying to use the cURL library, which is not installed or enabled on the server.

PHP Fatal error: Call to undefined function json_decode()

This error usually occurs when you are trying to use the json_decode() function, which is used to decode a JSON string into a PHP variable, but the function is not available.

PHP Fatal error: Cannot access empty property

This error message typically occurs in PHP when you are trying to access a property of an object or variable that has not been initialized or does not exist.

PHP float with 2 decimal places: .00

To format a float to have 2 decimal places in PHP, you can use the number_format() function.

PHP fopen() Error: failed to open stream: Permission denied

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.

PHP foreach with Nested Array?

To loop through a nested array in PHP using a foreach loop, you can use nested foreach loops.

PHP form - on submit stay on same page

To stay on the same page after a form submission in PHP, you can use the following steps.

PHP function to build query string from array

In PHP, you can use the http_build_query function to create a URL encoded query string from an array.

PHP generate file for download then redirect

In PHP, you can use the header() function to send a "Content-Disposition" header to prompt the user to download a file.

PHP header location-redirect doesn't work - why?

There are several reasons why a PHP header location redirect may not work:

PHP header redirect 301 - what are the implications?

A 301 redirect in PHP using the "header" function tells the browser that the page has permanently moved to a new location.

PHP How to add to end of array?

In PHP, you can add an element to the end of an array using the array_push() function.

PHP How to find the time elapsed since a date time?

You can use the DateTime class in PHP to find the time elapsed since a specific date time.

PHP how to go one level up on dirname(__FILE__)

You can use dirname(dirname(__FILE__)) to go one level up in the directory structure when using __FILE__ (which returns the current file's path).

PHP IF statement for Boolean values: $var === true vs $var

In PHP, a variable can be evaluated as a Boolean value in an if statement without the need to explicitly compare it to true or false.

PHP include relative path

In PHP, you can use the include or require statement to include a file with a relative path.

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.

PHP is not recognized as an internal or external command in command prompt

It sounds like you are trying to run the PHP command from the command prompt, but it is not recognized as a valid command.

PHP isset() with multiple parameters

The isset() function in PHP can take multiple parameters, and it will return TRUE if all of the variables passed to it have been set, and FALSE if any of them have not.

PHP json_decode() returns NULL with seemingly valid JSON?

There are a few possible reasons that json_decode() might return NULL when given what appears to be valid JSON.

PHP Mail, CC Field

In PHP, the "CC" field can be included in an email using the "mail" function by adding a "CC" header to the additional headers parameter.

PHP mkdir: Permission denied problem

The "Permission denied" error message is usually caused by a lack of write permissions for the user that is running the PHP script.

PHP mySQL - Insert new record into table with auto-increment on primary key

To insert a new record into a MySQL table that has an auto-increment primary key, you can use the INSERT statement with a list of comma-separated values.