Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove degree symbol from string php

Tags:

php

i have in database a string written with degree symbol, problem is when im printing it im getting it with unicode, each unicode is different even they are the same symbol, its driving me crazy how can replace the degree symbol for white space, im doing it this way:

 foreach ($video as $desc) {
          if (preg_match('/\/(.*?)"E/', $desc, $match) == 1) {
                $test = preg_replace('/[^\x20-\x7E]/', '', $match[1]);
                echo $test;
            }
         }

and my output is:

22\u00b017'44.1\"N, 114\u00b010'07.7\ 
22\u00b016'55.5\"N, 114\u00b009'16.9\
22\u00b018'50.6\"N, 114\u00b013'00.5\ 
22\u00b017'14.4\"N, 114\u00b009'04.0\
22\u00b023'16.3\"N, 114\u00b011'05.5\
22\u00b018'48.3\"N 114\u00b013'28.6\

each \u00b017 is the degree symbol printed in postman, but i dont want them, cant remove it or replace it since each one of them are different, theres no way i can set it manually

like image 930
lol69 Avatar asked Mar 08 '26 13:03

lol69


1 Answers

The degree symbol is \u00b0. You can use str_replace instead of RegEx to remove it:

str_replace('\u00b0', '', $test);
like image 127
Skip Avatar answered Mar 10 '26 03:03

Skip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!