-4

My database contains the followind string and is set to utf8_general_ci:

"Allg%u00e4ustra%u00dfe 9".

When I echo the string in php with var_dump(), I get the string that is set in the database, what I want to see is

"Allgäustraße 9".

I have tried to find a method to convert the string to a UTF-8 string with umlauts, but wasn't successfull.

Has anyone got an idea on where to start?

Adam
  • 28
  • 2
  • 1
    (The duplicate is about `\u`, not `%u` - but the regular expression from the accepted answer should be easy enough to modify accordingly.) – CBroe May 16 '22 at 13:51
  • 2
    Well, you got the string "Allg%u00e4…" from somewhere. This has nothing to do with UTF-8 or anything. You simply have a string with a percentage sign and some letters and numbers in it. Where'd it come from, and did you perhaps encode it weirdly at some point? – deceze May 16 '22 at 13:52
  • Why use utf8 encoding in the database if you're encoding utf8 characters as `%u00e4` and `%u00df` anyway? – KIKO Software May 16 '22 at 13:53
  • @CBroe thank you! I changed the function a bit and it worked. The string is coming in via an external mysl insert and for some reason has been encoded in this way. – Adam May 16 '22 at 14:27
  • I solved it with the following function as mentioned in the duplicate answer: `html_entity_decode(preg_replace("/%u([0-9abcdef]{4})/", "$1;", '%u00e4'))` html_entity_decode is used to convert it to an actual umlaut. In the above example this would be "ä". Thanks for the inspiration and help! – Adam May 16 '22 at 14:29
  • Something called uuencode() or equivalent. Fix that. – Rick James May 21 '22 at 21:14

0 Answers0