be careful with the syntax
If you have a text file cities.txt:
London
Alexandria
Belize
Roma
Calgary
Your php could be, e.g.
$output = shell_exec('sort cities.txt');
echo "
$output
";
?>
------------------
output will be:
Alexandria
Belize
Calgary
London
Roma