I have a weird dash in my text, which isn\'t being detected in a str_replace
.
Here is an example:
Sun: 10:00 – 3:00pm
I don
En -
Dash we're used to seeing
Em –
Dash that we're supposed to use most of the time where use "-".
Basically, it's a grammar thing.
Read up on Wikipedia: http://en.wikipedia.org/wiki/Dash
On a mac (with US Keyboard Layout) I get it hitting Alt+- , same as you get _ with shift+_
You don't need any special treatement to it as it were some chinese symbol. It is a valid character. Treat it as such: str_replace('–', 'em dash');
.
http://php.net/manual/en/function.str-replace.php#102465 jay suggested
$str = str_replace(chr(150), '-–', $str); // endash
$str = str_replace(chr(151), '--', $str); // emdash
That's an en dash. In php, the most portable way to get it is with html_entity_decode:
$endash = html_entity_decode('–', ENT_COMPAT, 'UTF-8');
echo str_replace($endash, '(en dash)', 'Sun: 10:00 – 3:00pm');
Note that this only works if your website encoding is UTF-8 and your editor encoding(or the encoding of the third argument to str_replace
) is as well. If you use another encoding (and you should use the same both for website and editor), replace the third parameter of html_entity_decode with its name.
For an alternative, if other answers don't work for you, like in my case, this 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);