Forum Moderators: coopster

Message Too Old, No Replies

Regex question.

         

Spanger

7:59 pm on Aug 21, 2007 (gmt 0)

10+ Year Member



In part of a php script I'm writing, I am trying to grab the number of videos a user has from the youtube Channel page.

I'm using regular expressions, but have run into a problem.

Running it like this:

$strToSearch = $result;
preg_match( '/Videos \([^0-9]*([0-9,]+)/i', $strToSearch, $vidmatches );

var_dump ($vidmatches);

Gives me this when I do var_dump:

9array(2) {
[0]=>
string(49) "Videos (<a href="/profile_videos?user=RonPaul2008"
=>
string(4) "2008"
}

It works dandy, but it grabs the number out of their username. =S

How can I get around this? Is there a way to specify "but not this number"?

HTML Source I'm coming from:

<span>Videos (<a href="/profile_videos?user=RonPaul2008dotcom" class="headersSmall">42</a>)</span>

Thanks for all your help! =D

Spanger

Spanger

3:18 pm on Aug 22, 2007 (gmt 0)

10+ Year Member



Anybody? =)

Spanger

SteveLetwin

6:43 pm on Aug 22, 2007 (gmt 0)

10+ Year Member



preg_match('/Videos \(.*>(\d+)</', $strToSearch, $vidmatches);

should do the trick, and if you're just matching against that line, rather than the entire file then you can reduce it to

preg_match('/>(\d+)</', $strToSearch, $vidmatches);