How-to articles, tricks, and solutions about PHP

How to get root directory in yii2

In Yii2, you can use the following code to get the root directory:

How to Get the Absolute Path to the Initially Run Script in PHP

In this short snippet, you will find a reasonable and accurate solution to a common PHP: how to get the absolute path to the initially run script.

How to Get the Client IP Address in PHP

Often it is needed to collect clients’ IP addresses for security purposes or for tracking the site activity. Here, we will show you how to do it in PHP.

How to Get the Current Year with PHP

On this page, you will get solutions to a common issue in PHP: how to get the current year.

How to get the first day of the current year?

In PHP, you can use the mktime function to get the Unix timestamp of the first day of the current year, then use the date function to format it as a date string.

How to Get the First Element of an Array in PHP

This snippet gives you an opportunity to learn how to get the first element of an array using PHP. You can choose among the provided functions.

How to Get the First Several Characters of a String in PHP

On this page, we represent to you the ways of getting the first five characters of a string in PHP. Keep on reading the snippet and check out the examples.

How to get the full URL of a Drupal page?

In Drupal, you can use the url() function to get the full URL of a page.

How to get the OS on which PHP is running?

You can use the php_uname() function to get the operating system on which PHP is running.

How to get the Query Builder to Output its Raw SQL Query as a String with PHP

If you want to grasp the way of getting a query builder to output its raw SQL query as a string using PHP, then you are in the right place.

How to get the server path to the web directory in Symfony2 from inside the controller?

In Symfony2, you can use the $this->get('kernel')->getRootDir() method inside a controller to get the server path to the web directory.

How to get time difference in minutes in PHP

To get the time difference in minutes between two dates in PHP, you can use the DateTime class and the diff() method.

How to get xdebug var_dump to show full object/array

To get xdebug to show the full contents of an object or array when using the var_dump function, you can use the xdebug.var_display_max_depth setting in your php.ini file.

How to handle Undefined Offset in laravel?

In Laravel, an "Undefined offset" error typically occurs when trying to access an array index that does not exist.

How to include a PHP variable inside a MySQL statement

To include a PHP variable inside a MySQL statement, you need to use prepared statements with bound parameters.

How to include Authorization header in cURL POST HTTP Request in PHP?

To include the Authorization header in a cURL POST request in PHP, you can use the CURLOPT_HTTPHEADER option and pass it an array of headers like this:

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.

How to Increase the File Upload Size with PHP

Here, we will assist you in finding the best way to increase the file upload size with the help of PHP arsenal. Read it carefully and follow the examples.

How to increment a number by 2 in a PHP For Loop

You can increment a number by 2 in a PHP for loop by using the increment operator (++) and adding 2 to it on each iteration.

How to increment letters like numbers in PHP?

In PHP, you can use the ++ operator or the += operator to increment letters, just like you would with numbers.

How to install all required PHP extensions for Laravel?

To install all of the required PHP extensions for Laravel, you will need to install the following PHP extensions on your server:

How to install bcmath module?

The bcmath extension is typically installed by default in most PHP installations.

How to install Laravel's Artisan?

To install Laravel's Artisan, you will need to install the Laravel framework on your machine first.