dqhbuwrwq692118284 2016-03-29 13:50
浏览 24

Wolfram alpha php不使用空格

I am working on a Raspberry Pi Mirror that will be controlled via speech. If a set command is not found, it will search Wolfram Alpha for an answer.

The script is written in php with addaptions from other questions here, but the problem is, it won't take any inputs with spaces. I've tried both foo+bar and foo%20bar but neither will work.

The script:

<?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>');
?>

The script runs normally without spaces, for example:

  • "Day" returns 1 day | 86400 seconds | 1440 minutes | 24 hours
  • "Pi" returns 3.141592653589793238462643383279502884197169399375105820974
  • "Time" returns 2:49:13 pm BST | Tuesday, March 29, 2016

Any help would be appreciated as I am rubbish with these kind of formatting problems :)

EDIT: Looking through the code, I don't know hy I didn't just use $contents = file_get_contents($url); instead of that very long way round, but it still won't accept the spaces : /

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器