<\/script>')

How to remove the "em" dash from a string?

I looked at other solutions here and here , but it does not work for me.

the 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>"; 

Exit

"ALIEN FILM MOVIE - PSP - Sony Boxed and Complete"

How to remove this character?

+8
php str-replace
source share
4 answers

Indicates an array of possible deletions,

 $s1clean = 'ALIEN - FILM - MOVIE – PSP – Sony - Boxed & Complete'; $s1clean = str_replace(["-", "–"], '', $s1clean); echo $s1clean; 

At startup

Ouput

ALIEN FILM MOVIE PSP Sony boxed and full

I just copied a weird feature and added it with the actual dash capability, and it worked.

Reading material

str_replace

+7
source share

Above did not work for me, but it happened:

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

Note: to use endash

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

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

+3
source share

Your dashes are a combination of a long dash – and hypen-minus (short dash) - - if you look at your code and title in a different font, you will see the difference.

At the beginning there are two short hyphens that delete your code, and some long dashes later than not removed.

Adding this will be fixed (this is a different dash, even if it doesn't look like one):

 $s1clean = str_replace('–', '', $s1clean); 

Edit

Alternatively duplicate the 2013 line of code, but use a hyphen minus < instead of 2013:

  $em_dash = html_entity_decode('&#x002D;', ENT_COMPAT, 'UTF-8'); 

If you are editing a font with a fixed width, they look the same, but they are not.

+2
source share

It works for me

 $title = "Hunting, Tactical & Outdoor Optics eCommerce Store ΓÇô $595,000 ΓÇâ SOLD"; $title = str_replace(html_entity_decode('&ndash;', ENT_COMPAT, 'UTF-8'), '-', $title); $title = str_replace(html_entity_decode('&mdash;', ENT_COMPAT, 'UTF-8'), '-', $title); 
+1
source share

All Articles