SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP String Functions


We can break each string after fixed interval and add string to each breaks. If interval or adding string is not given then a line break is added at the end of the string.
chunk_split(string, interval, string)
String is the main string which is to be broken, interval is the fixed interval after which string is to broken at each instance. 3rd parameter is the replacement string which is to be added after each split. Let us try some examples.
$str="This is a string and this is line end";
echo chunk_split($str);
The output is same
This is a string and this is line end
However in above line one line break is added at the end, to see the line break you can use the nl2br function like this.
echo nl2br(chunk_split($str))
You can see one line break is added at the end. Let us try another example
$str="This is a string and this is line end";
echo chunk_split($str,5,'*');
Output is here
This *is a *strin*g and* this* is l*ine e*nd* 
After five chars inculding space string is broken and one * is added.

Be the first to post comment on this article :

PHP String Functions
Post Comment This is for short comments only. Use the forum for more discussions.
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer