lyanaru Posted November 19, 2009 Share Posted November 19, 2009 Never been here before, but I hope this place is active. I am running a guild site based off of drupal. Anyways I am trying to use the preg_match_all function and having no luck whatsoever. I have never used regular expressions before so I have really no idea what I am doing. Here is my code: <?php $karmaurl = file_get_contents("http://domainnamehere.com/page/karma?raid=Twist&sort=karma"); preg_match_all("#<td width=150 class=\'karmakeep\'>(.*)</td>#i", $karmaurl, $nameout); preg_match_all("#<td width=50 class=\'numberkarmakeep\'>(.*)</td>#i", $karmaurl, $karmaout); echo "<table>"; echo "<tr>"; echo $nameout[0][0]; echo $karmaout[0][0]; echo "</tr>"; echo "<tr>"; echo $nameout[0][1]; echo $karmaout[0][1]; echo "</tr>"; echo "<tr>"; echo $nameout[0][2]; echo $karmaout[0][2]; echo "</tr>"; echo "<tr>"; echo $nameout[0][3]; echo $karmaout[0][3]; echo "</tr>"; echo "<tr>"; echo $nameout[0][4]; echo $karmaout[0][4]; echo "</tr>"; echo "</table>"; ?> The source I am pulling is basically just a table. What I would have intuitivly thought would be that I turn the bits I am interested in into an array then I can call the bits into my table, since they have td in them I dont need to have that and I would just grab the first 5 since that is what I want. What happens is I do get the first 5, but then it is repeated ad nausium taking the page 5 minutes to load and creating a royal mess. all I want are the first 5 entries. I only want them listed once not 1000 times. So what is causing this and what am I doing wrong? Is there a better way to go about pulling specific and similar pieces of information from source code? Quote Link to comment https://forums.phpfreaks.com/topic/182094-solved-preg_match_all-i-give-up/ Share on other sites More sharing options...
lyanaru Posted November 19, 2009 Author Share Posted November 19, 2009 Thanks in advance for any clues you guys can provide EDIT: Apologies to the mod, I didn't know there was a specific subforum for regex Quote Link to comment https://forums.phpfreaks.com/topic/182094-solved-preg_match_all-i-give-up/#findComment-960629 Share on other sites More sharing options...
lyanaru Posted November 19, 2009 Author Share Posted November 19, 2009 Probably worth noting that it does pull the information and lists it in a table correctly (a miracle in itself), it just seems to feel the need to repeat it more than I *thought* I told it to. Allot more. I actually am not exactly sure why it stops at all with the way it repeats. Would it just run out of memory and terminate? Why on earth does it repeat in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/182094-solved-preg_match_all-i-give-up/#findComment-960642 Share on other sites More sharing options...
cags Posted November 19, 2009 Share Posted November 19, 2009 I don't see any reason you should get more than 5 rows output on the screen. Due to the nature of preg_match_all it will match all instances, which could certainly take some time, but it should only output the 5 you have told it to. I was going to test it, but noticed you didn't actually provide the proper url. Quote Link to comment https://forums.phpfreaks.com/topic/182094-solved-preg_match_all-i-give-up/#findComment-960899 Share on other sites More sharing options...
lyanaru Posted November 19, 2009 Author Share Posted November 19, 2009 I don't see any reason you should get more than 5 rows output on the screen. Due to the nature of preg_match_all it will match all instances, which could certainly take some time, but it should only output the 5 you have told it to. I was going to test it, but noticed you didn't actually provide the proper url. I have narrowed it down a bit. It does in fact work exactly as intended on a blank page. Works perfectly even. However when I place it in a Drupal Block, all hell breaks loose. Works fine as a Drupal page as well. I suppose this is a discussion for the Drupal forums now. Quote Link to comment https://forums.phpfreaks.com/topic/182094-solved-preg_match_all-i-give-up/#findComment-961252 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.