bncplix Posted February 7, 2009 Share Posted February 7, 2009 Ok, so I am making something that will rip down a forum by parsing the thead IDS and the thread name. So far I have it working to rip off the forum IDS and print them, then I use that forum ID to try and go back and parse again to get the thread ID. It will only get the first forum name and then stop Here is the script: <?php $Site = file_get_contents('http://forum.tibia.com/forum/?subtopic=worldboards'); $boardArray[0] = ""; for ($i = 1; $i <= 74; $i += 1) { $splitA = explode('boardid=', $Site); $splitB = explode('">',$splitA[$i]); $boardArray[$i] = $splitB[0]; $splitC = explode('boardid='.$splitB[0].'">', $Site); $splitD = explode('</a><br>',$splitC[$i]); echo '<p> '.$i.'. '.$splitB[0].' - '.$splitD[0]; } ?> Does anybody know why it only grabs the first forum name and stops? It works fine getting the IDS. Also, if i just do echo 'boardid='.$boardArray[$i].'">'; It will print out excactly how it should split, so its not a mistake in that. Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/ Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 <?php $Site = file_get_contents('http://forum.tibia.com/forum/?subtopic=worldboards'); $boardArray[0] = ""; $splitA = explode('</a><br><font class="ff_info">This board is for general discussions related to', $Site); for ($i = 1; $i <= 74; $i++) { $splitB=explode('<td bgcolor="#D4C0A1" class="ff_std">',$splitA[$i]); $forum=strip_tags($splitB[1]); echo "<br/>$forum \n"; } ?> try this Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756900 Share on other sites More sharing options...
bncplix Posted February 7, 2009 Author Share Posted February 7, 2009 <?php $Site = file_get_contents('http://forum.tibia.com/forum/?subtopic=worldboards'); $boardArray[0] = ""; $splitA = explode('</a><br><font class="ff_info">This board is for general discussions related to', $Site); for ($i = 1; $i <= 74; $i++) { $splitB=explode('<td bgcolor="#D4C0A1" class="ff_std">',$splitA[$i]); $forum=strip_tags($splitB[1]); echo "<br/>$forum \n"; } ?> try this Thanks for trying, but nothing shows up now Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756910 Share on other sites More sharing options...
bncplix Posted February 7, 2009 Author Share Posted February 7, 2009 I tried doing it bassed on the idea you had (splitting between <font class="ff_info">This board is for general discussions related to the game world) and it works! Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756911 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 List of board ids from that link: $Site = file_get_contents('http://forum.tibia.com/forum/?subtopic=worldboards'); preg_match_all('~boardid=([^"]*)"~',$Site, $matches); echo "<pre>"; print_r($matches[1]); Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756914 Share on other sites More sharing options...
bncplix Posted February 7, 2009 Author Share Posted February 7, 2009 List of board ids from that link: $Site = file_get_contents('http://forum.tibia.com/forum/?subtopic=worldboards'); preg_match_all('~boardid=([^"]*)"~',$Site, $matches); echo "<pre>"; print_r($matches[1]); Woah thanks Just one more thing I am having a problem with I am now trying to get the thread IDS and the thread names from the actual sections, take here for an example: http://forum.tibia.com/forum/?action=board&boardid=8527 But some of them say Page 1, page 2, etc and it keeps printing out that part I am trying to make it just print the ID but it is also including this stuff: 2446049&pagenumber=1 So I used strpos to check if the & was there but it didnt seem to work (sometiems said it was there when it wasnt, sometimes said it wasnt there when it was) Do you know how I can spit the topics up easily? Thanks everybody im new to this Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756938 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 // example board. $board = file_get_contents('http://forum.tibia.com/forum/?action=board&boardid=8527'); preg_match_all('~threadid=(\d+)~',$board, $matches); echo "<pre>"; print_r($matches[1]); this will list all of the thread ids on the page. Note however that since each page number is a link with the same thread id, you're going to have an element with the same id for every page number in the thread that is listed on the page. If you don't want that, look into array_unique Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756962 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 Actually, didn't see that you also wanted thread names. // example board $board = file_get_contents('http://forum.tibia.com/forum/?action=board&boardid=8527'); preg_match_all('~threadid=(\d+?)"[^>]*>([^<]*)<~',$board, $matches); echo "<pre>"; print_r($matches[1]); // <-- array of thread id's print_r($matches[2]); // <-- array of thread names Added bonus: this will NOT match the ids from each page number. edit: changed the first capture to be non-greedy to make it more efficient Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756967 Share on other sites More sharing options...
bncplix Posted February 7, 2009 Author Share Posted February 7, 2009 // example board. $board = file_get_contents('http://forum.tibia.com/forum/?action=board&boardid=8527'); preg_match_all('~threadid=(\d+)~',$board, $matches); echo "<pre>"; print_r($matches[1]); this will list all of the thread ids on the page. Note however that since each page number is a link with the same thread id, you're going to have an element with the same id for every page number in the thread that is listed on the page. If you don't want that, look into array_unique Thanks, got it working with array_unique! Thanks for the help Edit: Cool you posted again before I could reply. I mainly needed the thread IDS and I was going to be able to grab the titles myself, but thanks you saved me time. Edit again: Woah this is weird, how do I print out specific indexes of these arrays? I never seen arrays setup like this where a single index contains all the data. Say I only wanted to print out the second thread ID and thread name from the array, how would I do that? I know normally I just pass it the index number but this is different Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756970 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 echo $matches[1][0]; // echo out id of 1st thread echo $matches[1][1]; // echo out id of 2nd thread echo $matches[1][2]; // echo out id of 3nd thread // etc... echo $matches[2][0]; // echo out title of 1st thread echo $matches[2][1]; // echo out title of 2nd thread echo $matches[2][2]; // echo out title of 3nd thread // etc... If that's too much for you, you can do something like this: $ids = $matches[1]; // your id array is now $ids so you can do for ex: $ids[1] for the 2nd id $titles = $matches[2]; // your title array is now $titles so you can do for ex: $titles[1] for 2nd title Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756982 Share on other sites More sharing options...
bncplix Posted February 7, 2009 Author Share Posted February 7, 2009 echo $matches[1][0]; // echo out id of 1st thread echo $matches[1][1]; // echo out id of 2nd thread echo $matches[1][2]; // echo out id of 3nd thread // etc... echo $matches[2][0]; // echo out title of 1st thread echo $matches[2][1]; // echo out title of 2nd thread echo $matches[2][2]; // echo out title of 3nd thread // etc... If that's too much for you, you can do something like this: $ids = $matches[1]; // your id array is now $ids so you can do for ex: $ids[1] for the 2nd id $titles = $matches[2]; // your title array is now $titles so you can do for ex: $titles[1] for 2nd title Yeah had just clicked reply then it said somebody already posted. I realized its a 2D array Thanks, I will donate to the site soon Quote Link to comment https://forums.phpfreaks.com/topic/144220-solved-explode-problem/#findComment-756984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.