Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/182094-solved-preg_match_all-i-give-up/
Share on other sites

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?

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 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. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.