2017-02-13 6 views
0

내 SEO 시스템에 대한 설명 메타 태그를 가져 오려고합니다.PHP 설명 태그 가져 오기 DomDocument

나는 Laravel 5.4

ScanController을 사용하고 있습니다 :

$description = $dom->getElementsByTagName('meta')->getAttribute('description'); 

지수 :

@foreach ($description as $node) 
{{$node->nodeValue, PHP_EOL}} 
@endforeach 

내가 새로 온 사람을 프로그램의 종류에 그렇게 도움이 필요합니다.

해결 방법 :

나는 수정을 발견!

@foreach ($description as $node) 
    @if($node->getAttribute('name')=='description') 
    {{$node->getAttribute('content'), PHP_EOL}} 
    @endif 
@endforeach 

나는 특히이 라인을 찾고 있었다 : 올바른 방향으로 나에게 킥을 준 주석 M : 시디키에

@if($node->getAttribute('name')=='description') 

감사합니다 :)

답변

0
$description = $dom->getElementsByTagName('meta'); 
@foreach ($description as $node) 
    @if ($node->hasAttribute('content')); 
     {{$node->getAttribute('content'), PHP_EOL}} 
    @endif 
    @else 
     {{ "No meta tag found with content attribute"}} 
@endforeach 

예를.

<meta name="description" content="this is the meta description content" /> 

당신은 태그를 FOREACH 및 속성을 얻을 필요가 아닌 nodeValue를, 난 내가 그렇게하는 방법을 잘 모릅니다 laravel 너무 가까이 @else 훨씬 좋은 아닙니다.

+0

안녕하세요, 답장을 보내 주셔서 감사합니다.이 방법을 시도했지만 아직 결과가 없습니다. 내가 '설명'을 '내용'으로 바꿀 때 그것은 무언가를 주지만 내가 원하는 것은 아닙니다. 다른 해결책이 있습니까? – itvba

+0

안녕하세요. 수정 된 답변을보세요 –

+0

다시 한번 감사드립니다. 그러나 여전히 작동하지 않습니다. "메타 태그를 찾을 수 없습니다 ...."라고 표시되어 있지만 메타 설명 태그가 있습니다. 또한 설명을 콘텐츠로 변경하면 모든 메타 태그가로드됩니다. – itvba