Reputation: 1710
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,
Upvotes: 4
Views: 3723
Reputation: 3833
One regular expression to replace a -
by a blank :
preg_replace('/-/',' ',$string);
You miss the regular expression delimiters.
Upvotes: 0
Reputation: 173572
Behold the strtr
:
$test = strtr($test, '-', ' ');
Btw, your original code has TEST-test
, that needs to be wrapped in quotes:
$test = 'TEST-test';
Upvotes: 10
Reputation:
Use php str_replace() for this thing
$test = 'TEST-test';
$test=str_replace('-', ' ', $test);
echo $test;
Upvotes: 0