HTML不显示字符

I'm running lighttpd 1.4.35 on Debian 8.2. I have a very simple html file with php code (php5) which calls a bash script and prints the output:

<html>
<body>
<?php
    $res = shell_exec("/var/www/html/run.sh");
    echo $res . " is the result";
?>
</body>
</html>

If that html file is called on firefox, the output is

 is the result

If I directly run php with that file (php index.php), the output is

<html>
<body>
13.00
 is the result</body>
</html>

So, where does the result get lost?


edit: The webpage source code from firefox is

<html>
<body>

 is the result</body>
</html>

edit: solved. bash script uses '~' which expands to wrong directory when the script is run from webserver.

The exec functions "only" return the contents of stdout, which is why you might miss an error message.
But you can redirect stderr to stdout, e.g. via

$res = shell_exec("/var/www/html/run.sh 2>&1");

shell_exec does not run if you're in safe mode, that could be the issue