$len = strlen(str);
$new_str;
for ($i=0;i<$len;$i++)
{
if($i%6==0)
$new_str = $new_str . " ";
$new_str = $new_str . $str[$i]; // or it is $str.chatAt($i) Please refer...
}
I Found a better way! Infact the best i have seen....
if ur string is $str and by break u meant a space (' '), all u have to do is...
$new_str = chunk_split($str,6," ");
i hope u understood... chunk_split(string, no. of chars, the break char)
2007-07-02 10:48:00
·
answer #1
·
answered by Ketchup 1
·
1⤊
0⤋
It's been a while since I've dealt with php syntax, but the concept is fairly simple.
Take you string and loop through every character of it. Inside this loop keep track of a separate counter. With each iteration through the loop, increment your little counter. Also perform a check inside that loop to see if the counter is ever at 6 (whichever number you want it to be). If it is 6, then insert your break character (there is a string function to do inserts at a certain position in the string) and then reset your little counter back to 0. It should perform that check every 6th character and insert the break.
2007-07-02 17:39:52
·
answer #2
·
answered by truextremeicon 3
·
0⤊
0⤋
Run a string length routine with a counter. Then each time you have reached the 6th letter you can append the string to another string variable with a space added. When finished with the string copy it back to the original variable or whatever else you want to do with it.
2007-07-02 19:01:29
·
answer #3
·
answered by Anonymous
·
0⤊
0⤋
try wordwrap().
The wordwrap function has a couple arguments that may be passed to it.
wordwrap($verylongstring, $chopsize,$splitstring,$alwayschop);
example splitting up every 6th character with
:
$broken = wordwrap($verylongstring,6,"
");
2007-07-02 17:54:56
·
answer #4
·
answered by Pekoe200 2
·
0⤊
0⤋
i don't know how to do that, but to make a break after a little while, you can use the
2007-07-02 17:38:12
·
answer #5
·
answered by kristin 2
·
0⤊
0⤋
fedest.com, questions and answers