【发布时间】:2015-05-03 07:27:34
【问题描述】:
尝试使用 php 实现自动建议。使用 awk 生成的自动建议列表
$input= $_GET["term"];
$suggest=array();
exec('awk \'BEGIN{FS=","}/.$input./{print $2,"-cost-",$1}\' 3.txt',$suggest);
echo json_encode($suggest)
代替 $input 来测试 autosuggest 我使用了一个 charachrecter eg.A,工作正常。但是我无法将动态字符作为 awk 的输入。 .$input 出了点问题。不知道怎么写转义字符
提前致谢
【问题讨论】:
-
您确定将 GET 参数替换为未经处理的 shell 命令是个好主意吗?如果我访问你的网站并通过
term=';rm -Rf / #,你不太可能喜欢这个结果。