질문입니다 채택완료

아래 소스를 view 스킨에 넣으면 링크1의 meta테그를 잘 보여주는데요

그대로 list스킨에 넣으면 첫번째 보여지는 게시물만 되고 그 다음게시물들이 사라져버립니다.

게시판목록에도 될수 있도록 수정좀 부탁드려요

Copy
<?php
function file_get_contents_curl($url)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

$html = file_get_contents_curl("$wr_link1");

//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');

//get and display what you need:
$title = $nodes->item(0)->nodeValue;

$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++)
{
    $meta = $metas->item($i);
    if($meta->getAttribute('name') == 'description')
        $description = $meta->getAttribute('content');
    if($meta->getAttribute('name') == 'keywords')
        $keywords = $meta->getAttribute('content');
}

echo "Title: $title". '<br/><br/>';
echo "Description: $description". '<br/><br/>';
echo "Keywords: $keywords";
?>

답변 2개

채택된 답변
+20 포인트
for ($i = 0; $i < $metas->length; $i++)

이부분의 카운트 변수를 $i가 아니라 다른걸로 바꾸세요 $k 라 든가 보통 리스트 스킨의 루프는 $i 로 시작하므로 루프안에 같은 변수가 있으면 무한루프로 빠질수 있습니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

추가 피해자 방지 https://sir.kr/conflictconsultation/245

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고