|
-
Jun 26th, 2008, 10:52 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Help with preg_match function
Hi all i am trying to use preg_match to get number of pages from a html that has this format :
HTML Code:
<div class="pagingOf">of </div><a class="pagingLink" href="javascript:__doPostBack('ctl00$cpMain$UserViewPictureControl$PagerTop','4')">4</a>
in this case i want to grab the number 4 but it never works. Could any one tell me what
PHP Code:
global $curl;
// Retrieve number of pages page.
echo 'Checking friends list... ';
curl_setopt($curl, CURLOPT_URL, './test.html');
curl_setopt($curl, CURLOPT_POST, 0);
$result = curl_exec($curl);
$headers = curl_getinfo($curl);
// Find out how many pages there are.
if (preg_match('~of <a href="(.+?)" class="pagingLink">([0-9]+)</a>~', $result, $matches))
{
$pages = $matches[2];
echo ' Number of pages: $pages ';
unset($matches);
}
-
Jun 26th, 2008, 11:12 AM
#2
Hyperactive Member
Re: Help with preg_match function
http://www.vbforums.com/showthread.php?t=527371
http://www.vbforums.com/showthread.php?t=527310
http://www.vbforums.com/showthread.php?t=527357
You have to be joking that you've posted almost the exact same thing 3 times and still haven't sorted it? I gave you code that worked perfectly fine.
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Jun 26th, 2008, 11:23 AM
#3
Thread Starter
Frenzied Member
Re: Help with preg_match function
RudiVisser thanks for your reply. But if you look closely you see the html is different then previous one!! Before posing this i tried your solutions it didn't work for my current html:
New html:
HTML Code:
of </div><a class="pagingLink" href="javascript:__doPostBack('ctl00$cpMain$UserViewPictureControl$PagerTop','4')">4</a>
old html:
HTML Code:
of <a href="javascript: GotoPage(4);" class="pagingLink">4</a>
-
Jun 26th, 2008, 11:32 AM
#4
Hyperactive Member
Re: Help with preg_match function
Well then you look closely and I'm sure you'll figure it out:
HTML Code:
of </div><a class="pagingLink" href="javascript:__doPostBack('ctl00$cpMain$UserViewPictureControl$PagerTop','4')">4</a>
PHP Code:
'of <a href="(.+?)" class="pagingLink">([0-9]+)</a>'
What comes first in the opening tag?
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Jun 26th, 2008, 11:45 AM
#5
Thread Starter
Frenzied Member
Re: Help with preg_match function
Thanks i fixed it :-)
PHP Code:
if (preg_match('%of </div><a class="pagingLink" href="(.+?)">([0-9]+)</a>%', $result, $matches))
{
$pages = $matches[2];
echo 'There are '.$pages.' pages.';
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|