![]() If we are writing our own custom string reverse code, then we can use this function to calculate the actual length of the string. This function can be used to get the length of a string to make the further required operations. contains in a string, then this 2-character special sequence can be considered as one. A developer should be aware enough of the functioning of this function. Length of the string and length of the reverse string of the same.Įcho "\nLength of the Reverse String: ".strlen($reverseString) īuilt-in function strlen() can be used to get the length of the string. ![]() In the above example code, we can see that the reversing string in php comes up with various stages, which include the getting length of the string, too, because the length of the given string helps the developer of the coder to loop through the end to the first position of the string. ![]() Use of the strlen() function in a program to reverse the given string. The length is showing one character lesser just because \n is being counted as one. In the above program, when we count the character, it will come up to 19 in the manual, but it the program output, we can see that the length is showing 18. Get the length of the given string after removing all the spaces from that string.Īn example program demonstrates the use of strlen() function with the string containing the special character and the escape character. We can consider this function as one of the easiest functions of the PHP string in nature, passing the string as a parameter to get the length. Given below are the examples mentioned : Example #1Īs we can see, there is not much in using this function due to the simplicity of this string function. This could be a bit tricky while coding in php using the string strlen() function. If we replace \ with any other character, then we will see the length 7 as an output. The above line of code gives the output as 6 rather than 7. $length = strlen($string) // lenghtof the string As we can see, we \n the 2 characters, but it will be counted as one while we will pass this as a parameter with the strlen() function. ![]() We should be careful while passing a string containing special sequence characters like \n,\t,\r, etc. Use of strlen() with the special sequence character as a string The above line of code given the length output as 16 as ‘WELCOME TO INDIA’ contains 16 characters, including the spaces. We can use the characters, special characters, URL, numeric values, and special sequence characters as part of the given string.Ĭode: $string = "WELCOME TO INDIA" // a stringĮcho strlen($string) // lenghtof the string It takes the string as a parameter and returns the length of that given string. How strlen() Function work in PHP?īefore moving ahead with the strlen, we must have a strong first upon which this function will be applied. There is nothing much with the syntax of this function. This returns the length of the string, and it will always be an Integer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |