2010-01-22 38 views
0

爲什麼showphp_Smartfm()根本沒有回顯。回聲你能聽到我嗎?

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

的後續問題,以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 not 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> 

回答

0

啓用所有錯誤reportings:

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

,並嘗試:

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

,看看發生了什麼

+0

的foreach($響應 - >測驗爲$測驗) { 的var_dump(quiz- $>的問題); // question var_dump($ quiz-> answer); // $ } Nothing和 foreach($ response-> quizzes as $ quiz) { echo var_dump($ quiz-> question); // question echo var_dump($ quiz-> answer); // answer } nothing 我相信我有錯誤報告?我如何確定? – Klanestro 2010-01-22 14:44:21

+0

上述內容完全沒有,我如何確保自己有錯誤報告? – Klanestro 2010-01-22 14:45:07

+0

更新了我的答案。 – Strae 2010-01-22 14:50:33

0

開始做'回聲調試'。

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

foreach($response->quizzes as $quiz) 
    { 
     echo $quiz->question; // question 
     echo $quiz->answer; // answer 
    } 
  1. 也許沒有$響應 - >測驗
  2. 也許這個問題,答案是空字符串
  3. 也許永遠不會被達到
  4. 這個代碼也許它輸出HTML標籤內,你從來沒有想過檢查查看源代碼
  5. 也許它在腳本的早些時候死去,並且你沒有打開錯誤報告。
+0

1-2。json文件中有$ response->測驗中的信息;請參閱http://stackoverflow.com/questions/2116963/navigating-objects-and-arrays 3.代碼是通過我所知道的,因爲它回聲的最後, 4.我住在查看源 5不這麼認爲,我看到我的錯誤,當我安裝它時,我確實打開了它。 – Klanestro 2010-01-22 14:52:58