2014-02-18 45 views
1

我想坐元採取這樣得到用PHP meta標籤不工作

<meta name="twitter:player" class="twitter_player" value="https://www.slideshare.net/slideshow/embed_code/31306908"> 
在PHP

,與get_meta_tags(URL)採取一切meta標籤,但元這樣誰擁有值爲空,我想取值從這個元我嘗試和

$doc= new DOMDocument; 
$doc->loadHTMLFile($values['ig_create_url']); 
$meta= $doc->getElementsByTagName('meta'); 
但是

它不工作,回來一個對象,具有0元

+0

嘗試更換'$ doc-> loadHTMLFile($值[ 'ig_create_url']);''與$ doc-> loadHTMLFile(的file_get_contents($值[ 'ig_create_url']));' –

+0

別t想要工作,我嘗試,但再次給一個對象0元素 – Laurentiu

回答

0

你說這個?

$doc= new DOMDocument; 
$doc->loadHTML('<meta name="twitter:player" class="twitter_player" value="https://www.slideshare.net/slideshow/embed_code/31306908">'); 
foreach($doc->getElementsByTagName('meta') as $tag) 
{ 
    echo $tag->getAttribute('value'); 
} 

OUTPUT :

https://www.slideshare.net/slideshow/embed_code/31306908 

EDIT :

相同相似的,但,我想加載一個鏈接從那裏獲取所有的meta標籤

您需要爲此使用file_get_contents()

$html = file_get_contents('http://yoururl.com'); 
$doc= new DOMDocument; 
$doc->@loadHTML($html); //<----- Pass the above $html variable here 
+0

相同但類似,但我想加載一個鏈接,從那裏獲得所有元標記 – Laurentiu

+0

@ user3270074,檢查編輯答案如何做到這一點。 –

+0

我嘗試你的消化,我讓$ doc = new DOMDocument; \t \t $ html = file_get_contents($ values ['ig_create_url']); \t \t $ doc-> loadHTML($ html); \t \t $ meta = $ doc-> getElementsByTagName('meta'); \t \t var_dump($ meta); – Laurentiu