Link to home
Start Free TrialLog in
Avatar of Heather Ritchey
Heather RitcheyFlag for United States of America

asked on

Add space between characters using php

I know this should be simple to figure out, but it's just not jumping out at me. I need to force a space between every character in a variable (possibly more than one space also).

Here is an example of that the variable will hold: BEJMCNHV702
And I need the result to be: B E J M C N H V 7 0 2

That is a reference id that a computer voice is reading to the sales people by phone. When I tested a call, the voice speaks so fast it's not only practically impossible to understand but there's no way the sales person will catch it to jot down. I want to test adding the spaces to see if I can slow down her speaking some. If the spaces aren't enough - the system will also respond to periods or commas. So if I could just get the right code snippet to add something between characters I can experiment.
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anwar Saiah
Anwar Saiah

$my_str = "BEJMCNHV702";
$str_arr = str_split($my_str);
//this will turn your string into an array.
$white_sp_str = implode(" ", $str_arr);
this will recreate the desired white spaced string.
Avatar of Heather Ritchey

ASKER

That worked great Tom - thank you.