Search code examples
phpstringinsertslash

Insert a slash in a string after every number except at the end (PHP)


i've a string

$string;

in this string i have a number, like 3743687

i wish to add a slash after every number, except at the end, so the result will be

3/7/4/3/6/8/7

is there a php function to do this, right ? any advice ? thanks


Solution

  • $string = '3743687';
    
    $newString = implode('/',str_split($string));
    
    var_dump($newString);