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?

Was it helpful?

Solution

Use $plaintext instead of result. Not sure why it works...it just does.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top