2012-01-22 2 views
1

그래서이 민간 기능이 있습니다PHP 컬는 XML 피드는 모든 데이터를 반환하지 않습니다 얻을 수

private function curl_get($url) 
{ 
    // Initiate the curl session 
    $ch = curl_init(); 

    // Set the URL 
    curl_setopt($ch, CURLOPT_URL, $url); 

    // Removes the headers from the output 
    curl_setopt($ch, CURLOPT_HEADER, 0); 

    // Return the output instead of displaying it directly 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 

    // Execute the curl session 
    $output = curl_exec($ch); 

    // Close the curl session 
    curl_close($ch); 

    return $output; 
} 

을 그리고이 링크 예를 들어 만약 내가 사용 http://www.metacafe.com/api/item/cb-xuFyGC0jJqPfhMoFnewj4Da_ZhHCz4L2/

지금 문제가 아무튼이다

[data] => SimpleXMLElement Object 
     (
      [@attributes] => Array 
       (
        [version] => 2.0 
        [source] => Metacafe 
       ) 

      [title] => Metacafe 
      [channel] => SimpleXMLElement Object 
       (
        [title] => SimpleXMLElement Object 
         (
         ) 

        [link] => http://www.metacafe.com/watch/cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ/ 
        [image] => SimpleXMLElement Object 
         (
          [url] => http://s.mcstatic.com/Images/MCLogo4RSS.jpg 
          [link] => http://www.metacafe.com 
          [title] => Metacafe 
          [height] => 65 
          [width] => 229 
         ) 

        [description] => SimpleXMLElement Object 
         (
         ) 

        [item] => SimpleXMLElement Object 
         (
          [id] => cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ 
          [author] => CBS 
          [title] => Romney Concedes South Carolina Primary 
          [link] => http://www.metacafe.com/watch/cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ/romney_concedes_south_carolina_primary/ 
          [rank] => 4.00 
          [category] => News & Events 
          [description] => SimpleXMLElement Object 
           (
           ) 

          [guid] => http://www.metacafe.com/watch/cb-GKeDVFevZxk_rNri_uz_K01azz3uV_ZZ/romney_concedes_south_carolina_primary/ 
          [pubDate] => 18 hours ago +0000 
         ) 

       ) 

     ) 

이 왜 설명하고 나에게 매우 중요하다 태그를 반환하지 않습니다 'T는 모든 데이터를 반환, 내가 할 모든이가? CDATA

답변

2

그것은 아니에요 인해 curl로하지만 어떻게 SimpleXML을 핸들 :

$xml = simplexml_load_string($stringFromCurl, 'SimpleXMLElement', LIBXML_NOCDATA); 

XML constants on PNP.net

이 SimpleXML이는 "모든 데이터"를 가지고, 그냥
+0

오, 몰랐습니다 ... 저는 XML을 처음 접했고 여러분에게 새로운 소식을 알게되었고 해결책을 얻었습니다. – Alex

+0

지금 내가해야 할 일은 [설명]에서 데이터 (태그, 설명, 제출)를 분리하기 위해 preg_match라는 것입니다. 맞습니까? – Alex

1

하지 참조, 텍스트 노드로 CDATA를 해석합니다 print_r()을 통해 볼 수 있습니다.

echo $your_simplexml_object->channel->item->description; 
+0

tnx하지만 LIBXML_NOCDATA가 문제를 해결했습니다. – Alex

+0

아니요, "문제"에 대해서만 해결되었습니다. 모든 데이터가 바로 거기에있어'print_r()'('LIBXML_NOCDATA' 제외)에 의해 보이지 않습니다. – salathe

+0

오, 알 겠어.하지만이 문제는 내 문제를 더욱 어렵게 만든다. 필요한 데이터 만 얻으려면'DOMDocument'를 통해'LIBXML_NOCDATA'를 사용할 때 거대한'preg_match'를 사용해야한다. 데이터가 필요합니다 – Alex

관련 문제