String Function Inside Php Programming Languages This tutorial is for string functions part – 2. Previous tutorials of
String Functions
Code for String Functions ” str_word_count(); ” (Screenshot1) :-
|
Screenshot1 |
<?php
$string = 'This is an example string & this is a tutorial.';
$string_word_count = str_word_count($string, 1, '&.');
print_r ($string_word_count);
?>
Output (Screenshot2) :-
|
Screenshot2 |
In this example, create third argument to the function and will count symbol as a word. In this way we can specify Symbol to function and will count different variable to the array.
Code for String Functions Str_Shuffle(); (Screenshot3):-
|
Screenshot3 |
<?php
$string = 'This is an example string.';
$string_shuffled = str_shuffle($string);
echo $string_shuffled;
?>
Output (Screenshot4):-
|
Screenshot4 |
In this example, string function str_shuffle is used to shuffle the string procedure i.e. used to randomize word or string. This is an example where string is shuffled as random words. This functions can be used generally when you want to auto generate words or string. Every-time you refresh it will generate randomize string at the time of giving output.
Refresh Browser (Screenshot5) :-
|
screenshot5 |
Every-time it will change your string to randomize it. Last time I used this function when I had uploaded image file and every time I want to regenerate the name by using function str_shuffle();. This is the best way you can use while uploading any file.
Code for string function str_shuffle(); (Screenshot6) :-
|
Screenshot6 |
<?php
$string = 'abcdefghijklmnop0123456789';
$string_shuffled = str_shuffle($string);
echo $string_shuffled;
?>
Output (Screenshot7):-
|
screenshot7 |
This is the best example for str_shuffle(); as I have generated random words for the string of Alphabets and Number.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..