Tag

PHP

Browsing

Today, We are going to learn PHP remove HTML tags from a string. We can remove HTML tags from the string using two ways. First, PHP provides the strip_tags function for removing HTML tags and preg_replace function for removing HTML tags from a string, Today, We learn both functions with the example.

  • Remove HTML tags using strip_tags function
  • Remove HTML tags using preg_replace function

PHP remove HTML tags from a string

We are going to learn the first example using strip_tags function.

Remove HTML tags using strip_tags function

We are using the strip_tags function for removing the HTML tags from the string. So, it’s very easy to remove HTML tags from a string. But the “strip_tags” add space after removing the tags from the string like.

The output of the above statement is “Hello world!” instead of “Helloworld!”.

So, let’s see the second example for removing HTML tags from a string and get the output like “Helloworld!” instead of “Hello world!”.

Remove HTML tags using preg_replace function

The output of the above function is “Helloworld!” instead of “Hello world!”.

We check the both function with the example Now, choose the which function is helpful for you and use it for removing HTML tags from a string.

If you face any issue after using above code please write the comment below.

Today, We are going to learn programmatically PHP create ZIP file. PHP provides ZipArchive class using that we can easily create the zip file. But Today, I am going to share function with you using that function you can easily create the ZIP file by passing the directory name or file name.

Suddenly, My client tells me to move his project from one server to another server and his use the shared hosting. So, I have only FTP detail at that time I created “createZip” function for creating the zip file of files or directories. I am going to share that function with you So, you can easily create the zip file without hard work using PHP. You just need to write single line code for PHP creating ZIP file.

PHP create ZIP file

Just past the “createZip” function anywhere on your project then you just need to call that function for creating the zip file like

If you need to create the zip file of the current directory then you need to pass dot except for the directory path like

Or else you should pass the full directory path like

After, Creating the ZIP file if you want to move it another server without download it on your local system then You can follow my tutorial “Download Archive file from URL

If you face any issue after using this code please write the comment below.

Today, We are going to learn how to Download zip file from URL using PHP. PHP download archive file using single line of code. We can easily download the any file using PHP single line of code. We use file_put_contents for download file.

PHP Download Archive file

You can download any types of file using this function like JPG, JPEG, EXE, PNG, MP4, MP3 etc…

This trick is very useful when you want to move project to new server. We don’t need to download project to local system and then upload it to new server. Just create zip file of the project and create PHP script to new server then directly download project file on new server using PHP script.

If you face any problem after using this code please write a comment.

Today, We are going to learn How to create Category tree from Array using PHP. Many times we need to create the parent and child category tree. Let’s make it easy with a single function. Yes, You can create the parent and child tree from Array using a single PHP function. Let’s follow the function and pass Array for creating parent and child category tree.

Category tree from Array

Finally, Our function is ready Now, you just need to pass the category array-like.

Now, let’s pass this Array to buildTree then check the output.

We got output something like below.

So, Our category tree is ready with parent and child hierarchy.

If you face any issue after using this code please write a comment.

Nowadays, PHP is a highly used language for Web development. So, Today we are going to learn file upload functionality. PHP file upload functionality is very easy and almost every application has file upload functionality. So, We must have knowledge about How to upload file on PHP. So, let see how to upload a file using PHP programming. You must have some basic knowledge of HTML for creating form.

PHP File upload

First of all, We are going to create the HTML form. So, let’s create the fileupload.html HTML file. Then write the following code.

We are ready with the HTML form. Now, let’s create the PHP code for handling the uploaded file and store it into the directory. First of all, create the fileupload.php PHP file. Then write the following PHP code.

Finally, We are ready with the PHP file upload code. Before, running PHP file upload example please create the uploads directory at the root directory of your project. Then after selecting a file and upload it and check the file is stored on uploads directory.

If you face any issue after following the code please write the comment below. We are always ready for help.

In the last example, We learn about single line comment. In this example, We are going to learn PHP multi-line comments. In multi-line comment PHP allow us to write multiple lines as a comment. Every developer must write the comment. So, another developer easily understands the code.

PHP multi-line comments

First of all, We are going to create a new PHP file for multi-line comment example. So, Let’s create a new file at “C:\xampp\htdocs\first\thecodignstuff.php” then write the below code.

Finally, We are ready with a multi-line comment example. So, Let’s run the file and check the output like

Hello World!20

The comments are not visible on output it’s only usable for a developer. If you face any issue on this example write the comment below.

PHP stands for Personal Home Page. PHP also was known as Hypertext processor language. Today, We are going to learn PHP Single Line comment example. Every language provides comment system. A developer must have habits to write down comment before writing the code. So, when another developer starts working or trying to read code his easily understand.

PHP Single Line comment

Every developer must have habits to write the comment. Let’s see, How we can write the single line comment on PHP. So, First of all, We are going to create a PHP file at “C:\xampp\htdocs\first\comment.php” then write the code like

When we run our example our output something looks like this.

Hello World!20

The Comments are not visible to the user. it’s only for developer use. If you face any issue on this example please write the comment below.

PHP stands for Personal Home Page. PHP also was known as Hypertext processor language. HTML stands for Hypertext Markup Language. Today, We are going to learn how we can embedding PHP in HTML. Actually, We are going to embedding HTML in PHP file. HTML is client side language and PHP is server-side language. PHP manage backend login and passing data to HTML. HTML handle that data and display to a user. Today, We are going to embedding “Hello World!” example with HTML.

Embedding PHP in HTML

We are going to embedding HTML in PHP. So, First of all, We should create a PHP file for our example. Let’s create the file at “C:\xampp\htdocs\first\thecodingstuff.php” then write the code like.

So, it’s too easy We can easily embedding HTML in PHP file like above example. Now, let’s run our example by following “http://localhost/first/thecodingstuff.php” URL. If you face any issue in this example write the comment below.

PHP stands for Personal Home Page. PHP is also known as Hypertext processor language. Today, We are going to start with our first PHP Program PHP Hello World. In any programming language, We start by writing out first ‘Hello World’ program in PHP.  So, Let’s we are going to starting with our first PHP program PHP Hello World.

PHP Hello World

First of all, We should create the PHP file for the Hello World program. So, let’s create the PHP file at “C:\xampp\htdocs\first\helloworld.php” then write the code like.

Now, let’s run that PHP file and check the output. Let’s open “http://localhost/first/helloworld.php” URL on your browser. The PHP program output something look like.

Hello World!

So, First PHP program output is print on the browser “Hello World!”. I hope this example is working for you. If you face any issue related this example please write the comment.