PHP How To

Variable Testing in PHP
Variable Testing in PHP

At times, we need to check whether a variable has been set, especially in cases where there is some user input from a form, and we need to verify it before saving it to the database. PHP provides a number of built-in constructs that can be used for this purpose.

Read More

How to Read Emails Using PHP
How to Read Emails Using PHP

You can connect to an email inbox using PHP’s IMAP functions. First, you need to open an IMAP stream to a mailbox.

Read More

PHP Shorthand If Else Using Ternary Operator
PHP Shorthand If Else Using Ternary Operator

Almost all the programs require evaluating conditions using if/else and switch/case statements. If-Else statements are easy to code and global to all languages. However, they can be too long. The ternary operator (?:) can replace a single if/else clause.

Read More

Associative Arrays in PHP
Associative Arrays in PHP

An associative array is composed of a collection of key and value pairs. Indexed array is an array with a numeric key.

Read More

How to Resize Image in PHP
How to Resize Image in PHP

Many times, you have to programmatically resize images. Maybe you have to create multiple sizes of the same image to serve on different devices. Maybe you need to resize images that your users are uploading. You can make use of the PHP's GD library to resize images in PHP. GD has all the necessary functions to manipulate images so you won't have to use any other 3rd party library.

Read More

How to Create Image using PHP
How to Create Image using PHP

Most of the image based operations can be performed by using PHP built-in functions. The image-based PHP functions are in GD library and you can use them for ctraeting an image.

Read More

Mapping Routes to Controllers
Mapping Routes to Controllers

Websites try to format their URLs to make them easier to remember instead of depending on the file that should handle that request. Also, all the requests go through the same file, index.php, regardless of their path. Because of this, we need to keep a map of the URL paths, and who should handle them.

Read More

MVC Structure in PHP
MVC Structure in PHP

Web applications can become more complex. The more functionality you add, the more difficult the code is to maintain and understand. It is for this reason that structuring your code in an organized way is crucial.

Read More

Display 2D Array as HTML Table in PHP
Display 2D Array as HTML Table in PHP

You can display a 2 dimensional array in PHP as a HTML table using nested foreach loop. For example, this is useful when you get rows of information from MySQL, and then you need to display its output as a table.

Read More

How To Get URL of Current Page in PHP
How To Get URL of Current Page in PHP

There are a lot of situations where you might need to get the URL of a webpage that any user might be currently visiting. For example, you may require you to dynamically generate the title of a webpage based on its URL. There are many ways in which you can obtain the URL of a webpage.

Read More

How To Redirect To Different URL in PHP
How To Redirect To Different URL in PHP

If you want all the visitor on the webpage https://example.com/initial.php to redirect to https://example.com/final.php, this can be done using several methods using PHP, JavaScript and HTML.

Read More

How To Calculate Difference Between Two Dates in PHP
How To Calculate Difference Between Two Dates in PHP

Calculating the difference between two dates is not as easy as it sounds. There are a lot of things that can go wrong if you are not careful. For example, you have to take both leap years and daylight saving time into consideration. Simply converting two dates to a timestamp and subtracting the values is not reliable in all cases. The PHP DateTime class takes care of all this.

Read More