2
There is a way to do the file_get_contents
perform a quick function within a loop?
Follows the code
<?php foreach ($links->result() as $value) : ?>
<?php
$url = $value->lnkUrl;
$domain = parse_url($url, PHP_URL_HOST);
$web_link = "http://".$domain;
$str = file_get_contents($web_link);
if(strlen($str)>0){
preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
if ( isset( $title[1] ) ) {
echo "<span class='directi_web' title='".$title[1]."'>". $title[1] ."</span>";
}else{
echo "<span class='directi_web'>...</span>";
}
}
?>
<?php endforeach; ?>
Uellington, the delay is not in itself related to the
file_get_contents
but rather because your script downloads an entire page to extract only the title. Maybecurl
be the most suitable for what you want to do.– gmsantos
And welcome to Stack Overflow. If you describe better what the purpose of your code can be better understood and useful to other people. Take a [tour] and see the guide [Ask] to better understand how the community works.
– gmsantos
Explaining the goal helps people propose more efficient solutions to their problem.
– brasofilo
I have a website that gathers content from various websites on the internet, is displayed in blocks on the home page, and would like to display the name of the link origin site.
– Uellington Palma