SamDOD Posted March 12, 2007 Share Posted March 12, 2007 Is there a way to use PHP to read a specific link and extract certain information from it. For example... To have the script read a website and to look for <table Id="somthing"> and get the <a tag and take the link and information under it? Does this make sense... is it possible... pls help! Thank you for your help Link to comment https://forums.phpfreaks.com/topic/42380-php-reading-a-link/ Share on other sites More sharing options...
Orio Posted March 12, 2007 Share Posted March 12, 2007 You got three options (that I know of) to get the data: - Using the regular file functions (best way imo if you simply need to read the file). You need allow_url_fopen enabled for that. - Using cURL (best way imo if you need to send post data and/or use session/cookies etc). You need the curl library installed for that. - Using sockets (never used it) Then, after you get the data, you could use regular expression (preg_match() or ereg()) to get the data you want. Hope it helps Orio. Link to comment https://forums.phpfreaks.com/topic/42380-php-reading-a-link/#findComment-205565 Share on other sites More sharing options...
SamDOD Posted March 12, 2007 Author Share Posted March 12, 2007 The issue i have is that it is not a page i am hosting and there for dont have acces too... I use the page regularly and am able to do things that effct the data and i want a way to use PHP to read the data so that i can redisplay it in a differant manner. Link to comment https://forums.phpfreaks.com/topic/42380-php-reading-a-link/#findComment-205578 Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 Here comes no.4 option. Thanks to fcicqbbs comment http://my2.php.net/manual/en/function.file-get-contents.php fcicqbbs at gmail dot com 04-Aug-2006 04:55 the bug #36857 was fixed. http://bugs.php.net/36857 Now you may use this code,to fetch the partial content like this: <?php $context=array('http' => array ('header'=> 'Range: bytes=1024-', ),); $xcontext = stream_context_create($context); $str=file_get_contents("http://www.fcicq.net/wp/",FALSE,$xcontext); ?> that's all. Link to comment https://forums.phpfreaks.com/topic/42380-php-reading-a-link/#findComment-205586 Share on other sites More sharing options...
SamDOD Posted March 12, 2007 Author Share Posted March 12, 2007 How do I have this code bit look for the specific <table id="something"> in side the link and get the content only out of that table and turn the <a tags that are there into var? Link to comment https://forums.phpfreaks.com/topic/42380-php-reading-a-link/#findComment-205594 Share on other sites More sharing options...
donynam Posted March 12, 2007 Share Posted March 12, 2007 use dom. http://my2.php.net/manual/en/ref.dom.php Link to comment https://forums.phpfreaks.com/topic/42380-php-reading-a-link/#findComment-205600 Share on other sites More sharing options...
SamDOD Posted March 12, 2007 Author Share Posted March 12, 2007 could you possibly give me an example of this? As it pertains to gathering the information in a <table with an ID and getting the <a tag href elemnts and the <img tag src that are in the <a and </a tags, from it? Link to comment https://forums.phpfreaks.com/topic/42380-php-reading-a-link/#findComment-205728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.