Wednesday 5 March 2014

String Functions In Php

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

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

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

string shuffled php
Screenshot3

<?php



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

$string_shuffled = str_shuffle($string);



echo $string_shuffled;



?>

Output (Screenshot4):-

php strings
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) :-

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

php strings functions
Screenshot6

<?php



$string = 'abcdefghijklmnop0123456789';

$string_shuffled = str_shuffle($string);



echo $string_shuffled;



?>

Output (Screenshot7):-

php strings
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..

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