String Function in php programming languages. This is tutorials for different String function inside php. How you can use them and why we want to use them??
Code for String Functions Example inside php (Screenshot1):-
String Functions Screenshot1 |
<?php $string = 'This is an example string.'; $string_word_count = str_word_count($string); echo $string_word_count; ?>
Output (Screenshot2):-
Screenshot2 |
In this example creating new variable string that will echo to particular string for example ‘This is an example string.’. Now we will doing few things along the tutorials. Now creating new variable which uses function and apply this function to this particular string. Now let see str_word_count this uses for count certain amount of words may be through user input and through database uses etc etc.. creating new variable $string_word_count and this will equal to function name which is str_word_count() this function take three arguments in total here i want only one argument required the one which is required is the actual string itself. So, I am just taking reference variable $string and echo out the result. And you can see result is 5 because in string we have 5 words. Full-stop does not count because it does not include in our word count.
Code for String Functions Example inside php (Screenshot3):-
Screenshot3 |
<?php $string = 'This is an example string.'; $string_word_count = str_word_count($string, 1); print_r ($string_word_count); ?>
Output (Screenshot4):-
Screenshot4 |
In this example in function i am including one more argument 1. it will define a string to array then define particular key to string. If we echo out it will display array and if we want to echo array key which string had particular key to array we have to use print_r. That willecho out array with key to particular string.
Code for String Functions Example inside php (Screenshot5):-
Screenshot5 |
<?php $string = 'This is an example string.'; $string_word_count = str_word_count($string, 1, '.'); print_r ($string_word_count); ?>
Output (Screenshot6):-
Screenshot6 |
In this example i am creating third argument to the function which counts every symbol as a word. In this example you can see i had include full-stop to the string which u can see in screenshot6.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..