foreach letter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

foreach letter

Post 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;
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: foreach letter

Post by requinix »

The simplest solution is probably

Code: Select all

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