2012-12-20 5 views
0

나는 이유를 배우기위한 워드 프레스 플러그인을 구축하고이 문제의 코드입니다 :종료 foreach 루프 완전히

// display latest facebook posts 
// Init a cURL resource 
$ch = curl_init("https://www.facebook.com/feeds/page.php?format=rss20&id=133869316660964"); 
curl_setopt($ch, CURLOPT_POST, false); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
// Make facebook think it is being accessed by a browser to avoid compatability issues 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7"); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$data = curl_exec($ch); 

// instanciate a new xml element 
$fb = new SimpleXMLElement($data); 
$i = 0; // set the counter for the foreach loop to 0 

echo "<ul>"; // begin the UL 

foreach ($fb->channel->item as $item) { 
    // foreach item within the tree perform this loop twice 
    $link = $item->link; // set the link address 
    $post = $item->description; // set the post data 
    echo "<li>" . $post, ' :::::: ', '<a href="' . 
    $link . '">' . $link, PHP_EOL . "</a></li>"; 
    $i++; 
    if($i == 2){ 
     exit(); 
    } 
} 
echo "</ul>"; 

그러나 나는이 볼 수있는 HTML을 검사 할 때 : (맨 아래에서 빠른 조각이)

846656&id=133869316660964 
</a></li> 

이, 난 = <이 때문에 사용 종료 완전히 스크립트를 중지 할 수 표시되는 위치를 $ foreach는 루프의 마지막 부분이다 나는 그 말에 수정하거나 존재입니다 다른 오류가 발생 했습니까?

답변

6

exit(); PHP 실행을 중지합니다. 루프를

PHP break

+0

당신이 감사를 종료

하지 종료를 종료 break;를 사용하려고하면 내가 :)가 표시됩니다 필요 무엇 올바른 때 그것이 나를 ;-) 수 있습니다. –

3

사용 휴식 및 종료는 PHP 스크립트의 전체 실행