Sunday, 20 October 2013

String Functions Part - 2

String Functions In PHP
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) :-
String function in php
String function part 2 (Screenshot1)
1
2
3
4
5
6
7
8
<?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) :-
String function in php
String function part 2 (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 functionand will count different variable to the array.
Code for String Functions Str_Shuffle(); (Screenshot3):-
String function in php
String function part 2 (Screenshot3)
1
2
3
4
5
6
7
8
<?php
 
$string = 'This is an example string.';
$string_shuffled = str_shuffle($string);
 
echo $string_shuffled;
 
?>
Output (Screenshot4):-
String function in php
String function part 2 (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. Everytime you refresh it will generate randomize string at the time of giving output.
Refresh Browser (Screenshot5) :-
String function in php
String function part 2 (Screenshot5)
Everytime 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) :-
String function in php
String function part 2 (Screenshot6)
1
2
3
4
5
6
7
8
<?php
 
$string = 'abcdefghijklmnop0123456789';
$string_shuffled = str_shuffle($string);
 
echo $string_shuffled;
 
?>
Output (Screenshot7):-
String function in php
String function part 2 (Screenshot7)
This is the best example for str_shuffle(); as I have generated random words for the string of Alphabets and Number.

Read More Extra Tutorials

No comments:

Post a Comment