...composed of an indefinite, perhaps infinite number of hexagonal galleries...

© 1994-2017. David Sklar. All rights reserved.

PHP one-liner of the day

Rahmin 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