Wednesday, 5 March 2014

String Function in Php

string functions
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 word count
String Functions Screenshot1

<?php



$string = 'This is an example string.';

$string_word_count = str_word_count($string);



echo $string_word_count;



?>

Output (Screenshot2):-

string functions
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):-

string functions
Screenshot3


<?php

$string = 'This is an example string.';

$string_word_count = str_word_count($string, 1);

print_r ($string_word_count);

?>

Output (Screenshot4):-

string functions in php
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):-

string functions in php
Screenshot5

<?php



$string = 'This is an example string.';

$string_word_count = str_word_count($string, 1, '.');



print_r ($string_word_count);



?>

Output (Screenshot6):-

string functions
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..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates