PHP Split String After Character
Last Updated : Jan 1, 2023
IN - PHP
In this tutorial we will show you the solution of PHP split string after character, today we will understand how to split string after character in php.
There are many method with help of which we can split string. Also, there are many meanings of split string here.
For this, here we are going to use two methods that are chunk_split() and other is explode(). Let us understand both.
Step By Step Guide On PHP Split String After Character :-
Here, the first one that is chunk_split() is used to split a string into series of small parts, we can also split it character by character.
Now, the next one is explode(), it is used where we want to split a string into arrays but in words. Let us go through them using codes.
<!DOCTYPE html> <html> <body> <?php $str = "you see that whole line is split using dots."; echo chunk_split($str,1,"."); ?> <?php $str = "in this each word is divided into array."; print_r (explode(" ",$str)); ?> </body> </html>
- First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
- Secondly, the <html> tag is used to indicate the beginning of an HTML document.
- As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
- Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
- Here, inside body you see that we use two different methods with are used for two different purposes.
- First one is done using chunk_split() method or say function and next one is by using explode() function.
- We also already created two different article in which we understand both the parts or say methods differently. We will understand them again in this article.
- In chunk_split() function, we see that there are three parameters. First, one is the string on which we want to apply split method.
- Next one is the number from which we want to apply the method whereas last one the character with help of which we want to divide string.
- Same like chuck, inside explode, and we have to give two parameters. First one the character with help of which we want to divide string and next is the string which we want to divide.
- One thing to note here that the explode function divides the whole string into arrays. We hope that you understand this article properly.
- At last, the <body> and <html> tags are closed with </body> and </html> respectively.
At last in conclusion, here we can say that with the help of this article we are able to understand login with session using database.
I hope this tutorial on PHP split string after character helps you and the steps and method mentioned above are easy to follow and implement.