Page 1 of 1
Breaking up strings and adding character inbetween.
Posted: Sat Oct 01, 2005 4:52 pm
by anthony88guy
Okay, Im trying to make a small function that would take a string such as $foo = "string"; and convert that to $foo = "s+t+r+i+n+g"; Basily breakdown the string and put it together adding a character inbetween each character of the string.
Anyideas?
Thanks
Posted: Sat Oct 01, 2005 5:21 pm
by Ree
Code: Select all
function strBreak($string, $separator)
{
$length = strlen($string);
$letters = array();
for ($i = 0; $i < $length; $i++)
{
$letter = substr($string, $i, 1);
array_push($letters, $letter);
}
return implode($separator, $letters);
}
echo strBreak('string', '+');
Posted: Sat Oct 01, 2005 5:59 pm
by anthony88guy
works great, I was thinking about using preg_split.
Thanks