简体   繁体   中英

Convert french accent to specific encoding in PHP

In php, what function can I use to convert the text 'pétition' to 'p%E9tition'.

I have tried with uft8_encode and uft8_decode with no success.

%E9 is an URL encoded escape character. You can achieve this by urlecode($string) .

If you want HTML escaping, you can either use htmlentities($string) (more encoding) or htmlspecialchars($string) (less encoding).

You can try to have a look at htmlentities. This link can help

When dealing with UTF-8 strings, you will need to decode the string (ie. with utf8_decode ) before encoding with urlencode to be used in a query part of a URL.

print_r( urlencode(utf8_decode('pétition')) );
// p%E9tition

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM