I'm invoking SWI-prolog from PHP, sending a question and getting result. I'm using exec() function for that:
$goal = "all_facts('S').";
$cmd = "/software/swipl/bin/swipl -f Domain.pl -g " . $goal . " -t halt";
The predicate all_facts() returns facts about counties, in this example - square.
There are a lot of facts about countries in Russian in the prolog file as it needed for my site. SWI-prolog returns an answer with Russian symbols and every thing is OK.
The problem rises when I'm trying to use Russian symbols in request, for example:
$goal = "all_facts('Столица').";
Then I'm running this request exactly in SWI-prolog, I get the correct answer. But then I'm asking it from PHP, I don't get the answer at all.
So, I guess, bugs appear while sending request and SWI-prolog gets distorted question, so it can't find an answer.
I've already changed encoding of SWI-Prolog (using environment variable LANG), encoding of page, tried to change encoding of PHP exec (not sure, if it worked). Maybe, I really need to change PHP exec encoding, but I am doing it wrong.
How can I do it?
Just in case, part of the prolog file:
facts('Австралия','S', 7686850).
facts('Австрия', 'S', 83871).
facts('Азербайджан','S', 86600).
facts('Австралия','Столица', 'Канберра').
facts('Австрия', 'Столица', 'Вена').
facts('Азербайджан','Столица', 'Баку').
all_facts(C):- findall(X:Y, facts(X,C,Y), All), write(All).
PHP code:
<?
$goal = "all_facts('Столица').";
$cmd = "/software/swipl/bin/swipl -f Domain.pl -g ".$goal." -t halt";
if (exec($cmd)) {
$output = exec($cmd);
}
else {
echo "Error!";
}
$output = str_replace(array("[","]"), "", $output);
$facts = explode(",", $output);
$length = count($facts);
echo "<ul>";
for ($i=0; $i<$length; $i++) {
$all_facts[$i]= explode(":", $facts[$i]);
echo "<li>", $all_facts[$i][0], " - ", $all_facts[$i][1], "</li>";
}
echo "</ul>";
?>
all_facts/1
call? – Paulo Moura