2013-09-02 3 views
1

HTML 일부 쿼리에 대해 아무것도 반환하지위키 백과 API는

<html> 
<head> 
</head> 
<form action="check2.php" method="POST"> 
    Search <input type="text" name="search" /> 
    <input type="submit" name="searchbtn" value="search" /> 
</form> 
</body> 
</html> 

PHP

<?php 
    $string = $_POST['search']; 
    $convert = rawurlencode($string); 
    $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&redirects&titles='.$convert; 
    if($_POST['search'] != '' || $_POST['search'] != null) { 
     $ch = curl_init($url); 
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
     $c = curl_exec($ch); 
     echo $c; 
    } else { 

    } 
?> 

그것은 내가 (예) "뉴욕"를 검색하면 XML을 반환하지만 내가 "를 검색하면 아무 것도 반환하지 않습니다 싱가포르 동물원 "

+1

'$의 c'의 내용이 무엇입니까? – Passerby

+0

'$ c'을 보셨습니까? – Soundz

+0

나는'parse_str ($ c, $ txArr);을 제거했다. var_dump ($ txArr);'그리고 $ c를 echo했다. 마지막 두 가지는 테스트 코드입니다. 미안합니다. – user1526570

답변

1

우선, 당신은 supposed to set a User-Agent입니다. 둘째, 검색이 아니라 특정 제목의 페이지에 대한 내보내기입니다. 당신은 action=opensearch을 찾고 있습니다.

https://en.wikipedia.org/w/api.php?action=opensearch&search=api&limit=1&namespace=0&search=Singapore_Zoo&utf8=true을 제공합니다

["Singapore_Zoo",["Singapore Zoo"],["The Singapore Zoo (Chinese: 新加坡动物园; pinyin: Xīnjiāpō Dòngwùyuán; Malay: 'Taman Haiwan Singapura'; Tamil: சிங்கப்பூர் விலங்குக் காட்சிச்சாலை), formerly known as the Singapore Zoological Gardens and commonly known locally as the Mandai Zoo, occupies 28 hectares (69 acres) on the margins of Upper Seletar Reservoir within Singapore's heavily forested central catchment area."],["https://en.wikipedia.org/wiki/Singapore_Zoo"]]