php insert hyphen into spaces in string

Solutions on MaxInterview for php insert hyphen into spaces in string by the best coders in the world

showing results for - "php insert hyphen into spaces in string"
Grayson
03 Nov 2019
1$test = "jjfnj 948";
2$test = str_replace(" ", "", $test);  // strip all spaces from string
3echo substr($test, 0, 3)."-".substr($test, 3);  // isolate first three chars, add hyphen, and concat all characters after the first three
4