I have a string $test='23487°';
How can I remove all the instances of the little circle that appears in the string using preg replace?
What to I enter for the regex to remove it?
EDIT - as Pekka says, str_replace is better I am now using that. But the little circle is still not recognized by PHP...
You don't need regex, just str_replace
:
$test = str_replace('°', '', $test);
The first parameter is the search term – the bit that will be found. The second parameter is the replacement string – the text that will be inserted instead. A blank string means "replace it with nothing", ie "remove it". The third parameter is the string on which to operate.
try with:
$test = preg_replace('/[^(\x20-\x7F)]*/','', $test);
this will replace all your non ascii characters from your string.
If you want to use preg_replace, you can do it like this:
$test = preg_replace('[°]', '', $test);
Also, for reference, here is a great site to test your regex: http://www.solmetra.com/scripts/regex/index.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.