/    Sign up×
Community /Pin to ProfileBookmark

url content extracting using PHP

Hi ,

i am working on a PHP code that would fetch me the” title and the description” from another web page something similar to [url]www.Digg.com[/url] .After searching a couple of Open source codes developed by some generous coder I found this piece of code:

I have tested this code and it works fine, but the confusion here is it only works from external internet and Iam not able to extract the contents when i use the same piece of code from my office intranet(Our intranet has full access to the internet ) and the best part is when i use the same url for fetching content from Digg.com from my office intranet it works fine.

The error I get is file_get_contents time out after 60 seconds
OR
I get a blank page result without any content

But the same piece of code when used outside of my intranet works perfectly fine.

Please let me know if you find anything incorrect!

Thanks

[CODE]<?php

if(isset($_POST[‘submitlink’]))
{
function getMetaTitle($content){
$pattern = “|<[s]*title[s]*>([^<]+)<[s]*/[s]*title[s]*>|Ui”;
if(preg_match($pattern, $content, $match))
return $match[1];
else
return false;
}

$url = $_POST[‘submitlink’];

$data = array();

// get url title
$content = @file_get_contents($url);
$data[‘title’] = getMetaTitle($content);

// get url description from meta tag
$tags = @get_meta_tags($url);
$data[‘description’] = $tags[‘description’];

$dom = new domDocument;

@$dom->loadHTML($content);

$dom->preserveWhiteSpace = false;

$images = $dom->getElementsByTagName(‘img’);

foreach($images as $img)
{
$imgurl = $img->getAttribute(‘src’);
$alt = $img->getAttribute(‘alt’);
//$size = getimagesize($imgurl);
//echo “Title: $alt<br>”;
//echo $imgurl;
//echo ‘<img src=”‘.$imgurl.'” title=”‘.$alt.'” width=”50px”/>’;

}

$formdata .= ‘<table><tr><td>Title:</td><td><a href=’;
$formdata .= ‘gethome.php?url=’;
$formdata .= $url;
$formdata .= ‘>’;
$formdata .= json_encode($data[‘title’]);
$formdata .= ‘</a></td></tr>’;
$formdata .= ‘<tr><td>Description:</td><td> ‘;
$formdata .= json_encode($data[‘description’]);
$formdata .= ‘</td></tr></table>’;
}[/CODE]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @karthikjayraj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...