我正在研究将通过语音控制的Raspberry Pi Mirror。如果找不到set命令,它将搜索Wolfram Alpha以获得答案。
这个脚本是用php编写的,其中有来自其他问题的addaptions,但问题是,它不会带任何带空格的输入。我已经尝试了foo + bar和foo%20bar,但两者都无法正常工作。
剧本:
<?php
$input = $_GET["input"];
$url = "http://api.wolframalpha.com/v2/query?input=" . $input . "&appid=XXXXX&format=plaintext&podindex=2";
echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
ob_start();
curl_exec($ch);
curl_close($ch);
$contents = ob_get_contents();
ob_end_clean();
function get($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
echo get($contents,'<plaintext>','</plaintext>');
?>
脚本正常运行,没有空格,例如:
1 day | 86400 seconds | 1440 minutes | 24 hours
3.141592653589793238462643383279502884197169399375105820974
2:49:13 pm BST | Tuesday, March 29, 2016
任何帮助都会受到赞赏,因为我对这些格式化问题很垃圾:)
编辑:仔细阅读代码,我不知道我没有使用$contents = file_get_contents($url);
而不是那么长时间,但它仍然不会接受这些空格:/