Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove 'em' dash from a string?

I've looked at other solutions here and here, but it's not working for me.

Code

$s1clean = 'ALIEN - FILM - MOVIE – PSP – Sony - Boxed & Complete';
echo $s1clean;
echo "<br><br>";

// Remove dash
$s1clean = str_replace('-', '', $s1clean);

// Remove em dash
$em_dash = html_entity_decode('&#x2013;', ENT_COMPAT, 'UTF-8');
$s1clean = str_replace($em_dash, '', $s1clean);

$em_dash2 = html_entity_decode('&#8212;', ENT_COMPAT, 'UTF-8');
$s1clean = str_replace($em_dash2, '', $s1clean);

$s1clean = str_replace('\u2014', '', $s1clean);

echo $s1clean;
echo "<br><br>";

Output

"ALIEN FILM MOVIE – PSP – Sony Boxed & Complete"

How do I remove this character?

like image 409
user3314053 Avatar asked Aug 14 '15 22:08

user3314053


1 Answers

The above didn't work for me but this did:

$s1clean = str_replace(chr(151), '', $s1clean); // emdash

Note: for endash use

$s1clean = str_replace(chr(150), '', $s1clean); // endash

from Jay: http://php.net/manual/en/function.str-replace.php#102465

like image 59
Aba Avatar answered Oct 08 '22 06:10

Aba