php - How to extract meta tags from multiple websites?

I am using this code to extract meta tags for one website but I am trying to get meta tags of multiple websites using a file.
<?php
$tags = get_meta_tags('https://demotiger.com');
$variable = $tags['description'];
echo $variable;
?>
I tried to modify this code to get it to work for multiple websites:
<?php
$file = file_get_contents('website-list.txt');
$tags = get_meta_tags('$file');
$variable = $tags['description'];
echo $variable;
?>
wesbite-list.txt
https://example.com https://example2.com
Error I am getting:
Warning: get_meta_tags($file): failed to open stream: No such file or directory in C:\someserver\www\index.php on line 3
Answer
Solution:
1.Since yourwesbite-list.txt
contains multiple lines, so you need to extract this file contents as an array. For that use file()
2.After that iterate over array and get the tags.
<?php
$websites = file('website-list.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($websites as $website){
$tags = get_meta_tags($website);
echo $tags['description'];
echo PHP_EOL;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: an exception occurred in the driver: could not find driver
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.