Posts for php

How to Make Simple Login Form in PHP

In this article, you will learn how to make a simple login form in PHP. Before following the example, you need to make sure that you have created a database name ‘codesource’, a table named ‘test’, a column named ‘username’ with type varchar(10) and another column named ‘password’ with type int(5). Then, insert the following […]

March 5, 2021 in Code examples

How to Concatenate Strings in PHP

In this article, you will learn how to concatenate strings in PHP. Let’s say you have 2 string variables. Concatenate Strings In order to concatenate strings, you can use the concatenation operator, . Note: The concatenation operator, . functions by concatenating its left and right arguments.

March 3, 2021 in Code examples

How to Add Days to Date in PHP

In this article, you will learn how to add days to date in PHP. Let’s say you have a string variable named ‘a’ with the value of a date. Add Days to Date In order to add days to date, you can use the date_create() method, date_add() method, date_interval_create_from_date_string() method and date_format() method. Note: The […]

March 3, 2021 in Code examples

How to Force Download File in PHP

In this article, you will learn how to force download a file in PHP.  Let’s say you want to download the google icon. Force Download File In order to force download a file, you can use the readfile() method . Please ensure that fopen_wrappers has been enabled in order to let the readfile() method read […]

March 3, 2021 in Code examples

How to Send Email With Attachment in PHP

In this article, you will learn how to send email with attachment in PHP. You need to ensure that you have configured your local installation for sending and receiving emails. Send Email With Attachment In order to send email with attachment, you can use the mail() method. Note: The mail() method functions by sending an […]

March 2, 2021 in Code examples

How to Get Domain Name From URL in PHP

In this article, you will learn how to get domain name from a URL in PHP. Let’s say you have a string variable named ‘a’ that has the value of code-source.tempurl.host’s article URL. Get Domain Name In order to get the domain name from a URL, you can use the parse_url() method and host parameter. […]

March 2, 2021 in Code examples

How to Get File Extension in PHP

In this article, you will learn how to get the file extension of a file in PHP. Let’s say you have a string variable named ‘a’ that has the value of a local file path. Get File Extension In order to get the file extension of a file, you can use the pathinfo() method. Note: […]

March 2, 2021 in Code examples

How to Calculate Age in PHP

In this article, you will learn how to calculate age based on birthdate in PHP. Let’s say you have 2 string variables containing date of birth and current date. Calculate Age In order to calculate age based on birthdate, you can use the date_diff() method and date_create() method. Note: The date_diff() method functions by calculating […]

March 2, 2021 in Code examples

How to Get Checkbox Values in PHP

In this article, you will learn how to get the checkbox values in PHP. Let’s say you have 4 checkboxes of colours. Get Checkbox Value in PHP In order to get the checkbox values, you can use the foreach() method. Result Note: The foreach() method functions by looping through all checked checkboxes and displaying their […]

March 1, 2021 in Code examples
Deven
Deven wrote

How to use sweet alert in PHP

In this short article, I will share how to use sweet alert in PHP. consider the following example. Step 1. Create a file Form.html with the following code: step 2. Create a file called main.js with the following code: step 3 – create file contact.php with the following code: Finally, Test and run it on […]

February 11, 2021 in Code examples