Page 1 of 1

foreach letter

Posted: Sat Aug 21, 2010 7:46 am
by JKM
Hi there, I want to split a string, and add '|' in front of each letter. Ex:

Code: Select all

$string = 'abc1d e fg8kd srf';
// output = |a|b|c|1|d| |e| |f|g|8|k|d| |s|r|f';
echo $output;

Re: foreach letter

Posted: Sat Aug 21, 2010 9:28 am
by requinix
The simplest solution is probably

Code: Select all

"|" . implode("|", str_split($string))