Lustre Posted April 16, 2010 Share Posted April 16, 2010 Hey, I'm new here. I need some help with parsing info from a website. The website contains lots of links like <span style="cursor:pointer" onclick="window.open('member.php?u=10362489002', '_self')"> And I want to find get the ID of each member from all of the links. (in the code above: 10362489002) This is the code I got so far, which does not return anything <?php $d = file_get_contents('http://url_here.com'); preg_match_all('/member.php?u=([0-9]+)"\'/', $d, $ma); var_dump($ma); ?> How should I make the pattern? thanks Link to comment https://forums.phpfreaks.com/topic/198726-parsing-info-from-website/ Share on other sites More sharing options...
callesson Posted April 16, 2010 Share Posted April 16, 2010 You can use GET function $member= $_GET["u"]; That will = 10362489002 Then you can select your database ("SELECT * FROM table WHERE id='$member' ") If thats what your looking for ? Link to comment https://forums.phpfreaks.com/topic/198726-parsing-info-from-website/#findComment-1042930 Share on other sites More sharing options...
xt3mp0r~ Posted April 16, 2010 Share Posted April 16, 2010 <?php $html = file_get_contents('http://siteurl.com'); preg_match_all('/member.php?u=(.*?)\'/', $html, $idz); print_r($idz); ?> Try this, if it works. Link to comment https://forums.phpfreaks.com/topic/198726-parsing-info-from-website/#findComment-1042939 Share on other sites More sharing options...
Lustre Posted April 16, 2010 Author Share Posted April 16, 2010 You can use GET function $member= $_GET["u"]; That will = 10362489002 Then you can select your database ("SELECT * FROM table WHERE id='$member' ") If thats what your looking for ? Nah this is not it, since the member ID is not a part of the URL, its just a link posted on a website. (which is not my site) <?php $html = file_get_contents('http://siteurl.com'); preg_match_all('/member.php?u=(.*?)\'/', $html, $idz); print_r($idz); ?> Try this, if it works. tried , but its all empty. it returns: Array ( [0] => Array ( ) [1] => Array ( ) ) Link to comment https://forums.phpfreaks.com/topic/198726-parsing-info-from-website/#findComment-1042958 Share on other sites More sharing options...
xt3mp0r~ Posted April 16, 2010 Share Posted April 16, 2010 <?php $html = file_get_contents('http://siteurl.com'); preg_match_all("/member.php\?u=(.*?)'/",$html,$idz); print_r($idz[1]); ?> Alright, i just checked it myself. This should work now. Link to comment https://forums.phpfreaks.com/topic/198726-parsing-info-from-website/#findComment-1043023 Share on other sites More sharing options...
Lustre Posted April 16, 2010 Author Share Posted April 16, 2010 <?php $html = file_get_contents('http://siteurl.com'); preg_match_all("/member.php\?u=(.*?)'/",$html,$idz); print_r($idz[1]); ?> Alright, i just checked it myself. This should work now. That almost worked, lol. I noticed that the "u" in "member.php\?u=(.*?)" screws up. I changed it to "member.php\?(.*?)" and it worked. Even though it returns strings such as ?s=021ed82677b143ddc8d96e1422f5fd5f&u=10122817001 I have no idea where the "?s=021ed82677b143ddc8d96e1422f5fd5f&" part comes from, since its not even in the source code. but that's ok. I'll use substr() to get the part I want. thank you! Link to comment https://forums.phpfreaks.com/topic/198726-parsing-info-from-website/#findComment-1043113 Share on other sites More sharing options...
Ken2k7 Posted April 16, 2010 Share Posted April 16, 2010 preg_match_all('#member\.php\?([^u]=[^&]+&)*u=(?<id>\d+)#i', $html, $ids); var_dump($ids['id']); Link to comment https://forums.phpfreaks.com/topic/198726-parsing-info-from-website/#findComment-1043124 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.