开发者

Echo can you hear me?

Why is showphp_Smartfm() Not echoing at all.

  foreach($response->quizzes as $quiz)
        {
          echo $quiz->question; // not echoing
          echo $quiz->answer; // not echoing
        }

Followup Question to Navigating objects and arrays http://github.com/klanestro/Vortoj

<html>
<body>

<?php
// Created by Talisman 01/2010 ★✩ 

$vorto = $_GET['vorto']; // Get the Word from Outer Space and Search for it!




if (isset($vorto))
    {
    echo " Your Direct search was " . $vorto .  ' <br></br> '; 
    } else {
        $Help = "No Vorto -> add ?vorto=TheWordYouWant to the end of this website";
        echo $Help;
    }



// Now Lets Search Alex's Vortaro, It uses jsonp
//  ex. http://vortaro.us.to/ajax/epo/eng/petas/?callback=?

/* Future Feature inproved language functinality */

// I used the capital AV to denote variables belonging to Alex's Vortaro
// #Plans for ( traduku.net, tn
//              :apertium.org,ap // I think its apertium.org
//              :reto-vartaro,rv 
//                      each root word has an xml file,  but how to you find this xml file?
//                      there is a xml link on the bottom of a search result,  but I can't figure 
//                      out a way to get to this info.
//              :project gutenburg, pg
//              :google books, gb
//  BUT NEXT UP ЄЭ smart.fm  
// it also assumes epo-eng

function getphp_AlexVortaro ($vorto)
    {
        $AVurl1 = "http://vortaro.us.to/ajax/epo/eng/"; 
        $AVurl2 = "/?callback=";
        $AVfinalurl= $AVurl1 . $vorto . $AVurl2;


        $AVcontent = file_get_contents($AVfinalurl) ;

        // Now we need to trim the () jsonp to json
        $AVcontent = substr($AVcontent, 1);
        $AVcontent = substr($AVcontent,0,-1);

        $AVDecode = json_decode($AVcontent);

        return ($AVDecode);
    }


function getphp_Smartfm($vorto)
    {
        $SFurl="http://api.smart.fm/items/matching/";
        // $SFurl2=urlencode($vorto); // +".json";
        $SFurl3="?language=eo&translation_language=en";
        $SFfinalurl = $SFurl . $vorto . ".json" . $SFurl3;  // you can change .json to .xml

        $SFcontent = file_get_contents($SFfinalurl);
        $SFDecode = json_decode($SFcontent);

        return ($SFDecode);
    }


$AVvorto = getphp_AlexVortaro ($vorto);
$SFvorto = getphp_Smartfm($vorto);



function showphp_AlexVortaro ($AVvorto)
    {
    $AVvortoshow = $AVvorto->text;
    echo $AVvortoshow;

    }

showphp_AlexVortaro ($AVvorto);



function showphp_Smartfm($SFvorto)
{
   // $objects is the array with all those objects
foreach($SFvorto as $object)
{
  echo $object->cue->language; // language

  foreach($object->responses as $response)
  {
    // if there are no quizzes, we skip the part below
    // we skip it because $object->quizzes will produce a warning or a notice
    // if "quizess" is no开发者_开发知识库t a member of the $object
    if(!isset($object->quizzes))
    {
      continue;
    }

    // quizess
    foreach($response->quizzes as $quiz)
    {
      echo $quiz->question; // question
      echo $quiz->answer; // answer
    }
  }
}


}

showphp_Smartfm($SFvorto);

?>

</body>
</html>


This fixed it

-    if(!isset($object->quizzes))
0
+    if(!isset($object->responses))

Go here http://github.com/klanestro/Vortoj/commit/625fce9ffbd2a4d45d7b8dffddff6986fe521a00#comment_43364


Start doing 'echo-debugging'.

print_r($response); 
print_r($response->quizzes);

foreach($response->quizzes as $quiz)
    {
      echo $quiz->question; // question
      echo $quiz->answer; // answer
    }
  1. Maybe there are no $response->quizzes
  2. Maybe the question and answer are empty string
  3. Maybe this code is never being reached
  4. Maybe it's outputting inside an HTML tag and you never thought to check View Source
  5. Maybe it's dying way earlier in the script and you don't have error reporting turned on.


Enable all the error reportings:

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//or directly edit your php.ini !

and try with:

foreach($response->quizzes as $quiz)
    {
      var_dump($quiz->question); // question
      var_dump($quiz->answer); // answer
    }

and see what is going on

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜