테스트 사이트 - 개발 중인 베타 버전입니다

질문입니다 채택완료

하아아 3년 전 조회 3,387

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

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

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

 

</p>

<p><?php

function file_get_contents_curl($url)

{

    $ch = curl_init();</p>

<p>    curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);</p>

<p>    $data = curl_exec($ch);

    curl_close($ch);</p>

<p>    return $data;

}</p>

<p>$html = file_get_contents_curl("$wr_link1");</p>

<p>//parsing begins here:

$doc = new DOMDocument();

@$doc->loadHTML($html);

$nodes = $doc->getElementsByTagName('title');</p>

<p>//get and display what you need:

$title = $nodes->item(0)->nodeValue;</p>

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

<p>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');

}</p>

<p>echo "Title: $title". '

';

echo "Description: $description". '

';

echo "Keywords: $keywords";

?></p>

<p>

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

답변 2개

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

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

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

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

n
3년 전

추가 피해자 방지 https://sir.kr/conflictconsultation/245" rel="nofollow noreferrer noopener" target="_blank">https://sir.kr/conflictconsultation/245

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

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

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

로그인