php – chunk_split

<?php
$str=”0123456789″;
echo chunk_split($str, 2, ‘:’);
// It can be used to split a string into smaller chunks.
// In the above coding-string 0123456789 is chunk splited into 01:23:45:67:89:.ie each 2 string is splited by a “:”

?>

Example 1

In this Example chunk_split function will add * after 1 character, Because We are using 1 as second input to this function chunk_split($string,1,”*”)
<?php
$str = “Hello world!”;
echo chunk_split($string,1,”*”);
?>

Output: H*e*l*l*o* *w*o*r*l*d*!

Example 2

In this Example chunk_split function will add * after 10 character, Because We are using 1 as second input to this function chunk_split($string,10,”*”)

<?php
$str = “Hello world!”;
echo chunk_split($string,10,”*”);
?>

Output:
Hello worl*d!

Advertisements

1 Comment »

  1. amitmondal said

    Nice tutorial….thanks for this post…..
    Please visit this link for learn more script.
    http://amitmondal.wordpress.com/

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: