How-to articles, tricks, and solutions about PHP

How to include External CSS and JS file in Laravel 5

To include external CSS and JavaScript files in a Laravel 5 application, you can use the asset helper function.

Laravel 5.2 - pluck() method returns array

The pluck method is used to retrieve a list of a single column from a database table.

How to find day of week in php in a specific timezone

To find the day of the week in PHP in a specific timezone, you can use the date function and specify the timezone using the date_default_timezone_set function.

How to get file URL using Storage facade in laravel 5?

To get the URL of a file using the Storage facade in Laravel 5, you can use the url method.

PHP exec() vs system() vs passthru()

The exec(), system(), and passthru() functions are all used to execute external programs in PHP.

Remove excess whitespace from within a string

To remove excess whitespace from within a string in PHP, you can use the preg_replace() function with a regular expression that matches any sequence of one or more whitespace characters.

PDO get the last ID inserted

To get the last inserted ID using PDO, you can use the PDO::lastInsertId() method after inserting a row into the database.

Select mySQL based only on month and year

To select data from a MySQL database based on the month and year, you can use the MONTH and YEAR functions in your SELECT statement.

PHP - warning - Undefined property: stdClass - fix?

It looks like you are trying to access a property of an object that has not been defined.

.rar, .zip files MIME Type

In PHP, you can use the finfo_file function to determine the MIME type of a file.

Parsing domain from a URL

To parse the domain from a URL in PHP, you can use the parse_url function, which will return an associative array containing information about the URL.

How to print a debug log?

To print a debug log in PHP, you can use the echo function to output a string to the web page or the print_r function to output the contents of a variable.

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.

Only variable references should be returned by reference - Codeigniter

This error message in Codeigniter indicates that you are attempting to return a variable by reference, but only variable references can be returned by reference.

How do I implement basic "Long Polling"?

Here's an example of how you can implement Long Polling in PHP:

How to install MySQLi on MacOS

To install MySQLi on a Mac, you will first need to install the MySQL database server on your machine.

How to validate array in Laravel?

In Laravel, you can use the validate method on the Validator facade to validate an array of form data.

How to check if PHP array is associative or sequential?

To check if an array is associative or sequential in PHP, you can use the array_keys() function and compare the resulting array of keys with the original array.

Access denied for user 'homestead'@'localhost' (using password: YES)

This error message indicates that there was a problem connecting to the MySQL database with the provided credentials.

php.ini & SMTP= - how do you pass username & password

To pass a username and password to the SMTP server in the php.ini file, you can use the following format:

XAMPP: Couldn't start Apache (Windows 10)

There are a few things you can try if you are having trouble starting Apache in XAMPP on Windows 10:

Prevent nginx 504 Gateway timeout using PHP set_time_limit()

You can use the set_time_limit() function in PHP to increase the maximum execution time of a PHP script.

Package php5 have no installation candidate (Ubuntu 16.04)

I'm sorry to hear that you're having trouble installing PHP on your Ubuntu 16.04 system.