...

View Full Version : Resolved Simple regex help



The_Return
09-21-2009, 12:49 AM
I'm trying to capture the 242334 from this


<a href="member.php?u=242334">*Username*</a>


My code doesn't seem to work maybe its because the "*" in the username?



if(preg_match_all('#<a.*href="member.php\?u=(\d+)".*>#Uis', $buf, $match))

MattF
09-21-2009, 01:42 AM
if(preg_match_all('#<a.*href="member.php\?u=(\d+)">#Uis', $buf, $match))

The_Return
09-21-2009, 03:18 AM
hmm still not working I'll post my whole code



<?php

if (isset($_POST['id'])) {

$pages = $_POST['pages'];


$f = fopen("http://forum.ebaumsworld.com/memberlist.php?&pp=30&order=asc&sort=username&aim=a&page=$pages","r");
while( $buf = fgets($f,1024) )
{
if(preg_match_all('#<a.*href="member.php\?u=(\d+)">#Uis', $buf, $match))
{
for( $i = 0; $match[1][$i]; $i++ )
{
$numbers = strtolower($match[$i]);
if(!is_numeric($numbers)) continue;
$file = fopen("id.txt", "a");
print ("$numbers<br>");
fputs($file, "$numbers\r\n");
fclose($file);
}
}
}

if ( !$buf = fgets($f,1024) )
{
echo "User ids have been added to the list";
}
}
?>

MattF
09-21-2009, 01:40 PM
Change:



if(preg_match_all('#<a.*href="member.php\?u=(\d+)">#Uis', $buf, $match))
{


to:



if(preg_match_all('#<a href="member.php\?u=(\d+)">#Uis', $buf, $match))
{
print_r($match);


and post the output.

The_Return
09-22-2009, 01:49 AM
Doesn't display anything :(, vbulletin changed their format in their newest version instead of having the whole link it shows just the members.php thats when I view the source in firefox but when in google chrome it shows something else take this forum as an example

http://forum.ebaumsworld.com/memberlist.php?&pp=30&order=asc&sort=username&aim=a&page=1

in internet explore 8 when I view source I get this


http://screensnapr.com/u/h3rugb.png

what I have noticed is that number I need is in the td class alt1Active where the id is this has not changed in all the browser version I viewed, all that needs to be removed is the"u"

MattF
09-22-2009, 01:57 AM
Untested. Try:



if (preg_match_all('#<a href="member.php\?.+u=(\d+)">#Uis', $buf, $match))

The_Return
09-22-2009, 02:01 AM
Thanks that worked perfectly :)

MattF
09-22-2009, 02:15 AM
You're welcome. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum