Tutorialio aims to be the first and last website you have to visit when looking for answers to common programming questions. We will try to post answers to one frequently asked question everyday so keep visiting. Here is a list of our recently published tutorials.
Many times, the strings that you are manipulating in a PHP project will have extra spaces that need to be removed. For instance, you might want to replace multiple spaces with a single space or you might want to get rid of all the whitespace in a string. Similarly, you might be planning on stripping all the whitespace from either the left or the right end of a string. In this tutorial, you will learn about different techniques to do all that quickly and efficiently.
String.replace() method to replace a simple substring with another string. One problem with this method is that it only replaces the first occurrence of the word or substring. In this tutorial, we will learn about different methods which can be used to replace all occurence of a substring inside the main string.
If you are working on a website or project which deals with images, there will most probably come a time when you will have to programmatically resize those images. Maybe you have to create three different sizes of the same image to serve on different devices. Maybe you need to resize images that your users are uploading. Loading a 1920*1080 image when 96*54 image will do is just a waste of resources.
In this article, we will write different functions that will 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.
When looking for a word, character or substring inside another string, it is very common to check if the main string starts with given substring. Basically, every technique that worked when looking for a subtring inside another string will also work when we need to check if the substring only occurs at the beginning. However, this is a more specific situation and we can perform the check more efficiently using slightly different methods. In this tutorial, you will learn about different methods which can be used to check if a string starts with given word or substring.
Many times, when working on a PHP project, you deal with an array which has some unwanted or empty array elements. This is especially true if you have no control over the values populated into the array. For example, you might have to store user input into an array and some of that input might contain unwanted empty strings. In this tutorial, you will learn about different methods which can be used to remove empty elements from an array. We will also learn how to remove other elements with a specific value.
Location object returned by
window.location property. Each of these properties can either return the full URL or a part of it.
In some projects, an element could be considered hidden only if its
display property is set to
none. In other projects, the element would be considered hidden if its opacity is set to 0 or its visible property is set to
hidden. In this post, we will discuss how to determine the visibility of an element based on all these properties.
Every now and then, we have to deal with strings which contain unwanted characters either at their beginning or the end. PHP provides a lot of methods which can be used to remove these characters. Each of them has its advantages and disadvantages. In this tutorial, we will discuss all these methods in detail so that you can choose the one that works best for your situation.
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.
Fortunately, the PHP
DateTime class takes care of all this for us. In this tutorial, we will use the different methods from this class to get the difference between two dates.
In this tutorial, you will learn how to use the
Date object and its methods to get all the necessary information about the current date and time.
Let’s say you have a string and and you want to check if it contains a specific word, character or substring. This can be done with the help of
strpos(), regular expressions,
strstr() and a few more functions. In this article, we will discuss the pros and cons of each of these methods in detail.
Every now and then, you will have to read and process a large file in PHP. If you are not careful when reading a large file, you will often end up exhausting all the memory of your server. However, there is no need to worry because PHP already provides a lot of inbuilt functions to read large files (by large I mean files with size over 1GB) either line by line or one chunk at a time. In this article, you will learn about the pros and cons of all these techniques.
In this tutorial, we will discuss all these methods along with their pros and cons in detail.
Let’s say you have an array and you want to delete one or more elements from that array using PHP. Maybe you have to delete an element with a specific value or maybe you have to delete multiple consecutive elements. In this article, you will learn about different inbuilt PHP functions that can help you remove one or more elements based on their key or value.