我在swi-prolog和php之間創建了一個接口。 PHP編寫命令,它希望prolog在文件上運行,然後執行系統調用,以便prolog運行該文件。問題是,當文件上有特殊字符(如á,í,ê,ê等等)時,這些字符在prolog的輸出中被替換爲\ uFFFD,我知道這個代碼點是unknown/unidentified codepoints,但是我一直沒有成功解決我在互聯網上發現的問題。如果從終端自己運行文件,它會顯示正確的字符,只是當php從exec或shell_exec運行時,它似乎失去了原因。Prolog和php編碼
這裏的使用的代碼,第一個PHP:
$arquivo = fopen("/home/giz/prologDB/run.pl", w);
$run = <<<EOT
go :-
consult('/home/giz/prologDB/pessoasOps.pl'),
addPessoa(0,'$name','$posicao','$resume','$unidade','$curso','$disciplina',$alunos,[]),
halt.
EOT;
echo $run;
fwrite($arquivo, $run);
$cmd = "prolog -f /home/giz/prologDB/run.pl -g go";
exec($cmd, $output);
echo "\n";
print_r($output);
echo "\n";
序言代碼:
addPessoa(LOCAL, NOME, POSICAO, RESUMO, UNIDADE, CURSO, DISCIPLINA, ALUNOS, REFERENCIA):-
write('Prolog \nwas called \nfrom PHP \nsuccessfully.\n'),
write('pessoa('),
write(LOCAL),
write(',\''),
write(NOME),
write('\',\''),
write(POSICAO),
write('\',\''),
write(RESUMO),
write('\',\''),
write(UNIDADE),
write('\',\''),
write(CURSO),
write('\',\''),
write(DISCIPLINA),
write('\','),
write(ALUNOS),
write(','),
write(REFERENCIA),
write(').\n'),
make.
是否有人知道如何使它正確地解釋串?
除了您必須在變量中轉義引號這一事實之外,您正在談論的字符在哪裏進入場景?你是否檢查過所有的編碼匹配(終端,IDE等)? – 2012-07-05 20:12:51