-1

I have a Java app that I'm calling thru PHP exec. The Java shows the middot on the command line : "·"

But when the code is called from PHP in a utf-8 html page I Have a "?" instead of the "·".

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <form method="post" action="essai2.php">
            <input type="text" name="texte" />
            <input type="submit" value="Valider" />
        </form>
        <?php 
            echo "input text : ".$_POST['texte'];
            exec("/usr/bin/java -jar runner.jar ".$_POST['texte'], $variable);
            echo "<br>output text : ".$variable[0];
        ?>
    </body>
</html>

Any clue ? (I tried htmlentities, htmlspecialchars. And text file on command line is utf-8)

To give some more grasp to the issue : on command line I do

java -jar runner.jar "le agriculteur est mort"

I get

[le·la, agriculteur·trice, est, mort]

while on webserver I get

[le?la, agriculteur??trice, est, mort]

the hex code of all this (following Rick James comment) is :

5b6c653f6c612c206167726963756c746575723f3f74726963652c206573‌​742c206d6f72745d

hope it helps

Mehdi_debout
  • 71
  • 1
  • 6

2 Answers2

0

ok for some reason php exec change the locales. so the answer according to PHP exec change encoding

was to set locales before doing the exec :

$locale='fr_FR.UTF-8';
setlocale(LC_ALL,$locale);
putenv('LC_ALL='.$locale);

and VOILÀ !!

Mehdi_debout
  • 71
  • 1
  • 6
0

If you start with hex B7, but end up with ? (3F), that is probably because the text was encode in latin1 (or any of cp1250, cp1251, cp1256, cp1257, dec8, geostd8, greek, hebrew, latin5, latin7), the n treated as if it were UTF-8. B7 is not a valid first-byte for any utf8 character.

Rick James
  • 135,179
  • 13
  • 127
  • 222