I have a weird dash in my text, which isn’t being detected in a
Here is an example:
Sun: 10:00 – 3:00pm
I don’t know if the dash will show up on here.. but when it is inserted into my table, it is like a square box with the characters
It looks a lot like an
– – when viewing the source, there is no special characters, just the dash.
str_replace('–', '', $var);
The above replace doesn’t seem to catch it, has anyone else had this trouble before?
$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);
- Dash we’re used to seeing
– 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');.
$str = str_replace(chr(150), '-–', $str); // endash $str = str_replace(chr(151), '--', $str); // emdash