How-to articles, tricks, and solutions about PHP

Setting PHPMyAdmin Language

To set the language for PHPMyAdmin, you can do the following:

PHP include relative path

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

Curl and PHP - how can I pass a json through curl by PUT,POST,GET

To pass a JSON object through cURL using the PUT method, you can use the following command:

mysqli_fetch_array while loop columns

The mysqli_fetch_array() function in PHP is used to retrieve rows of data from a MySQL database query result, and return the data as an array.

Composer: file_put_contents(./composer.json): failed to open stream: Permission denied

This error message is indicating that the script is trying to write to the file "composer.json" in the current directory (indicated by "./"), but it doesn't have the necessary permissions to do so.

How to create virtual column using MySQL SELECT?

To create a virtual column using a MySQL SELECT statement, you can use the AS keyword to assign a name to an expression in the SELECT statement.

Format Timezone for Carbon Date

To format a timezone for a Carbon date in PHP, you can use the format() method and include the e or I format codes.

Best way to test for a variable's existence in PHP; isset() is clearly broken

In PHP, the isset() function is used to check if a variable has been set, meaning that it has been declared and is not equal to NULL.

Get PHP class property by string

In PHP, you can use the $ operator to access an object's properties by name.

Disabling Strict Standards in PHP 5.4

To disable strict standards in PHP 5.4, you can add the following line of code to your PHP script:

syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

This error message is typically encountered when there is a problem with the syntax of a string in PHP.

Codeigniter $this->db->get(), how do I return values for a specific row?

The $this->db->get() function in CodeIgniter is used to retrieve data from a database table.

How do I recursively delete a directory and its entire contents (files + sub dirs) in PHP?

In PHP, you can use the rmdir() function to remove a directory, and the unlink() function to remove a file.

Declaration of Methods should be Compatible with Parent Methods in PHP

In PHP, when a class inherits from another class, it is said to be a subclass or derived class.

Access a global variable in a PHP function

In PHP, you can access a global variable within a function by using the global keyword.

How to check if a date is in a given range?

In PHP, you can use the DateTime class to check if a date is within a given range.

Output an Image in PHP

In PHP, you can output an image using the built-in function header() to set the content type to an image format and the readfile() function to read the image file and output its contents.

How can I check if an array element exists?

In PHP, you can use the "in_array" function to check if an element exists in an array.

Laravel Query Builder where max id

In Laravel, you can use the Query Builder's max method to retrieve the maximum value of a specific column.

How to check if variable is array?... or something array-like

In PHP, you can use the "is_array" function to check if a variable is an array.

PHP remove all characters before specific string

You can use the strstr() function in PHP to remove all characters before a specific string.

Switch in Laravel 5 - Blade

In Laravel 5, the Blade templating engine provides a "switch" statement that allows you to compare a variable to multiple values and execute different code for each match.

PHP preg replace only allow numbers

You can use the preg_replace() function in PHP to only allow numbers in a string using a regular expression.

How do I create a copy of an object in PHP?

In PHP, you can create a copy of an object using the clone keyword.

Laravel - Model Class not found

If you are receiving an error stating that a specific Model class cannot be found in Laravel, there are a few possible causes: