How could I prevent escapeshellarg function from escaping accented characters?

632 Views Asked by At

PHP native function escapeshellarg is escaping accented character on my machine

$stringWithAccentedChar = 'Hello à è World';
echo escapeshellarg($stringWithAccentedChar);
// Output : Hello World

I tried with locale US or FR, iso-8859-1 or UTF-8. No change.

I think it's a matter of settings because every php tester online I used doesn't escape those characters.

How could I prevent the removal of accented character ?

1

There are 1 best solutions below

0
wiktor On BEST ANSWER

When escapeshellarg() was stripping my non-ASCII characters from a UTF-8 string, adding the following fixed the problem:

<?php
setlocale(LC_CTYPE, "en_US.UTF-8");
?>

Source: https://www.php.net/manual/en/function.escapeshellarg.php#99213