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'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 0096
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?
The hyphen is mostly a normal character in regular expressions. You do not need to escape the hyphen outside of a character class; it has no special meaning.
Â, â (a-circumflex) is a letter of the Inari Sami, Skolt Sami, Romanian, and Vietnamese alphabets. This letter also appears in French, Friulian, Frisian, Portuguese, Turkish, Walloon, and Welsh languages as a variant of the letter "a".
Using str_replace() Method: The str_replace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (” “).
The trim() function in PHP removes whitespace or any other predefined character from both the left and right sides of a string. ltrim() and rtrim() are used to remove these whitespaces or other characters from the left and right sides of the string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With