PHP one-liner of the day
14 Apr 2004Rahmin Pavlovic asked:<blockquote>I’m trying to take a string like: ‘abcd’ and add a fwd slash every other char, like: ‘a/b/c/d/’ Any suggestions?</blockquote>My reply was:
$str = implode(‘/’,preg_split(‘/\b|\B/’,$str,-1,PREG_SPLIT_NO_EMPTY)).’/’;
But Jon Baer had a better idea:
chunk_split($string, 1, ‘/’);
Tagged with php