When I enter the string DIN 2080 Fräseraufnahmen SK 30
into the browser, it encodes it as DIN%202080%20Fr%C3%A4seraufnahmen%20SK%2030
, and the API properly reads this. However, in a PHP script to call the same API, when I encode the string using the function rawurlencode()
, it is encoded as DIN%202080%20Fra%CC%88seraufnahmen%20SK%2030
. This causes the same API to misidentify the string as not matching. How do I encode the string in PHP so that it will be same same as encoded by the browser?
Browser:
DIN%202080%20Fr%C3%A4seraufnahmen%20SK%2030
PHP rawurlencode()
:
DIN%202080%20Fra%CC%88seraufnahmen%20SK%2030
3
Answers
You can use the PHP Normalizer class to convert the string using the same normalization form as the browser uses. You do need to have the
intl
PHP extension installed for this to work though.This should be how this would work:
Based on my experience, it seems like the character set of the editor(vscode…) is the problem.
Check whether the editor character set is UTF-8.
good luck.
enter image description here
Your desired output requires replacing spaces with "%20" you can try:
does that answer your question or you want some different approach?