Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression replacing dash with space

I have a problem how do i replace a single dash(-) with a single space.

I tried the following

$test = TEST-test;
preg_replace('\-', '/s', $test);
echo $test;

but no result.

thx,

like image 325
Msmit1993 Avatar asked Oct 19 '25 20:10

Msmit1993


1 Answers

Behold the strtr:

$test = strtr($test, '-', ' ');

Btw, your original code has TEST-test, that needs to be wrapped in quotes:

$test = 'TEST-test';
like image 131
Ja͢ck Avatar answered Oct 21 '25 11:10

Ja͢ck