Question: I need to change a string from a format such as  

`abcdefghijklmnopqrstuvwxyz` to `ab/cd/ef/abcdefghijklmnopqrstuvwxyz`.

What is the most efficient way to do this in php?

Examples:

`123456789` would become `12/34/56/123456789`

`gwn58yh045bgw0r8` would become `gw/n5/8y/gwn58yh045bgw0r8`

Answer: 
You want `preg_replace`. This code should do it:

```
$input = 'abcdefghijklmnopqrstuvwxyz';
$output = preg_replace('/^(..)(..)(..).*$/', "$1/$2/$3/$input", $input);

```

This take the first 3 groups of two characters `(..)` and prepends them (`$1`, `$2`, `$3`) to the original string, with slashes.

Demo: <http://codepad.org/WueutXZA>
**Update**

*Note:* Since Jeff B beat me to the `preg_replace` solution, his is the most efficient. But just to provide another (completely unreadable) alternative...

```
$inStr = 'abcdefghijklmnopqrstuvwxyz';

$temp = substr($inStr,0, 6);
$outStr = substr_replace(
            substr_replace(
                substr_replace($temp, '/', 2, 0)
            , '/', 5, 0)
          , '/', 8, 0);

echo($outStr . $inStr);

```