Author

Admin

Browsing

Today, We are going to learn PHP remove non-empty directory. PHP provides rmdir function using that we can easily remove any directory. But When you are going to remove a non-empty directory using rmdir it’s fire exception. You can’t able to remove non-empty directory message something like The directory is not empty.

PHP remove non-empty directory

So Let’s see, how we can remove a non-empty directory. I am going to share function with you using that function you can able to remove a non-empty directory.

First of all, Place this function with your code. Now, you just need to pass the directory path as a parameter to deleteDirectory function like.

finally, Now you can able to remove a non-empty directory. You can get more detail about this function from here.

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

Today, We are going to learn Laravel Extract zip/archive file using chumper/zipper. In the last article, we will learn how to create a zip file.  Also, We are going to use chumper zipper package to extract the zip file. First of all, We are going to install the package by the following command.

Laravel Extract zip/archive file using chumper/zipper

Once the package has installed we have to update the Providers and Aliases. Let’s open the config “config/app.php” file then append the Providers and Aliases like below.

The Chumper Zipper package is ready to use. Now, We going to extract the zip file. Let’s create the function to extract the zip file.

First of all, I get the zip file path for passing the first argument on the Zipper function. As a second argument, You should pass the valid directory where you want to extract the zip file. Now, run the code and check the zip file is an extract or not.

If you face any issue on extract zip file please write the comment below.

Today, We are going to learn Laravel create zip/archive file using chumper/zipper package. We can easily create a zip file and download it using chumper zipper package Laravel. We are going to create a ZIP file including folders or files step by step.

Laravel create zip/archive file using chumper/zipper

First of all, We are going to install chumper zipper package for creating a zip file. Let’s open your command prompt and go to the project directory then follow below command.

Once the package is installed we have to append the Provider and Aliases into the Laravel config file. Let’s open “config/app.php” config file then append Provider and Aliases like.

The chumper zipper package is ready for use. Now, We are going to create a zip file of images folder and download it using the route. Let’s write the sample code to create a zip file and download it.

First of all, I create the array of images exists on the images folder using PHP glob method. Then I called the Zipper::make method for creating a zip file. The first parameter is the folder name or file name where you want to create or stores zip with a name. Then I have to pass the images array to the add method.

After, creating the zip file we can easily download it using download method. If you face any issue during creating a zip file or download zip file please write the comment below.

Today, We are going to learn Laravel 5 Hello World application. We all hear about the Laravel Framework. Laravel is the most popular object-oriented PHP Framework. Laravel is easy for developing the application and secure framework. We are going to learn step by step Hello World application of Laravel. First of all, We are going to install Laravel.

The composer is required for installing Laravel application. If the composer is not installed then install it first.

Laravel 5 Hello World application

Let’s see how to install the latest version of the Laravel

If you want to install an older version of the Laravel then follow below command.

You have to pass the folder name for installing Laravel my folder name is thecodingstuff. You can change or replace the command with your folder name.

Once the Laravel installation is complete just goto the project directory by the following command.

Now, Let’s run the Laravel project follow the command

Now, You can access the Laravel project by following the link.

If you want to run the Laravel project directly without firing any command. You can follow the below link.

Now, We are going to create the route, controller and view file code. First of all, Let’s create the route.

Create Route

Open the laravel route file for create route. If you install Laravel 5.3 or above version then you will find the route file at “routes/web.php” location. If you install Laravel 5.2 or lower version then you will find the route at “app/Http/routes.php” location.

Let’s open your route file and write the route like.

Laravel provides all types of routes like GET, POST, UPDATE, DELETE etc.. For Now, we create the GET route for Hello World application. The first parameter is the URL prefix “hello-world” and the second parameter is the Controller name and function name.

Create Controller

Let’s create the controller for Hello World example. Create a new file at “app/Http/Controllers/ExampleController.php” location. Now, open the ExampleController.php and write the below code.

Create View

Now, We are going to create a view file. Create a new file at “resources/example.blade.php” location. Open example.blade.php file then writes below code.

The Hello World example is over Now, let’s run the application and check the Hello World example. Open below URL

If you get any error on this page writes the comment below.

Today, We are going to learn PHP Converting Timestamp into a time ago. PHP provides date functions for print the date. PHP date function returns the date something like.

print date(“Y-m-d H:s:i”);

output : 2019-02-26 6:39:45

PHP date function returns date like the above format. Also, You can customize the output of date function using date options. But you want to display the time like a time ago then you can achieve that PHP code that we are going to learn today.

  • a second ago
  • a minute ago
  • a days ago
  • a month ago
  • a year ago

PHP Converting Timestamp into a time ago

We can easily get the date like above. I have created a function for convert date to time ago string. Using that function you can easily convert date and time.

Use the above function into your code and then pass the date and time argument on the function then check the output. let’s see the example of how to use converElapsedTime function.

echo converElapsedTime(‘2017-06-23 19:23:15’);

output : a year ago

So, It’s too easy to convert a date and time to time ago string. If face any issue after using this function please write the comment below.

Today, We are going to learn update or create the post publish time. We see the post publish date on many blogs the post publish 3 hours ago. So, How we can change the date format something like Converting Timestamp into a time ago on our WordPress blog. I am going to share step by step guide for date change like.

  • a second ago
  • a minute ago
  • a days ago
  • a month ago
  • a year ago

Yes, We can display the date like this on WordPress blog. So, let’s see how we can change the date format like this.

Converting Timestamp into a time ago in WordPress

We can implement this code by plugin or theme. So, let’s see If you want to implement this code by theme then open the functions.php file. If you want to implement this code by plugin hen open the mail file of your plugin. Then after, following the below function for converting the timestamp into a time ago string.

Now, let’s we are going to call the hook for change the publish date of Blog in WordPress.

We have created the hook get_the_date, the_date, the_time, get_the_time for change the WordPress Blog time. Just follow the above code then check the blog time is changed on your site.

If you face any issue or date is not changed like shown in an example please write the comment below.

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 find the records between two different numbers like find the product that price is between 5 to 25. So, Let’s see how we can find the records between two numbers. MySQL between two numbers in Laravel. We can find the records between two numbers using two ways in Laravel. Let’s see the first way how we can find the records between two numbers.

MySQL between two numbers in Laravel

You can achieve the same result using less than and greater than instead of whereBetween function. let’s see the second way for finding the records.

You can achieve the same result on the both example. So, it’s too easy to find the product between two number.

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