Use $plaintext instead of result. Not sure why it works...it just does.
Wolfram Alpha PHP API Script not Displaying Equation Results
-
14-04-2022 - |
Question
I have the following code that gets results from Wolfram Alpha:
<?php
include 'WolframAlphaEngine.php';
$engine = new WolframAlphaEngine( 'API-KEY' );
$resp = $engine->getResults("2+2");
$pod = $resp->getPods();
$pod = $pod[1];
foreach($pod->getSubpods() as $subpod){
if($subpod->plaintext){
$plaintext = $subpod->plaintext;
break;
}
}
$result = substr($plaintext, 0,strlen($plaintext)-3);
echo $result;
?>
If I search for text such as "George W Bush" it displays what it should, but if I search equations such as 2+2 then it doesn't show the results. Any clues?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow