php - How to remove 'em' dash from a string?

Solution:
This specifies an array of possible removals,
$s1clean = 'ALIEN - FILM - MOVIE – PSP – Sony - Boxed & Complete';
$s1clean = str_replace(["-", "–"], '', $s1clean);
echo $s1clean;
When ran,
Ouput
ALIEN FILM MOVIE PSP Sony Boxed & Complete
I simply copied the weird dash and added it with the actual dash possibility and it worked.
Reading Material
Answer
Solution:
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
Answer
Solution:
Your dashes are a mix of long dash{-code-1}
and hypen-minus (short dash)-
-if you view your code and the title in a different font you will see the difference.
There are 2 short dashes at the start that your code removes, and some long dashes later that it doesn't remove.
Adding this will fix it (this is a different dash even if it doesn't look like one):
$s1clean = str_replace('{-code-1}', '', $s1clean);
Edit
Alternatively duplicate the 2013 code line but use the hyphen-minus's code002D
instead of 2013:
$em_dash = html_entity_decode('-', ENT_COMPAT, 'UTF-8');
If you edit in a fixed width font both appear the same, but are not.
Answer
Solution:
This one works for me
$title = "Hunting, Tactical & Outdoor Optics eCommerce Store ΓÇô $595,000 ΓÇö SOLD";
$title = str_replace(html_entity_decode('–', ENT_COMPAT, 'UTF-8'), '-', $title);
$title = str_replace(html_entity_decode('—', ENT_COMPAT, 'UTF-8'), '-', $title);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.