Jump to content

Recommended Posts

Hi,

 

So I'm having some trouble with regex... of course...

 

Here's what's happening.

 

I'm building a Google scraper. It goes out, does a search for forums register pages, and grabs the links to them all.

 

I have everything working, I just need the regex to grab the proper links.

 

In my head I see the script grabbing all links that have register.php inside the href area. This is what my regex looks like right now.

 

<a href="(*)register.php" class=l>

 

However, I get this error when it runs.

 

Warning: preg_match_all() [function.preg-match-all]: Compilation failed: nothing to repeat at offset 9 in C:\wamp\www\forumfinder.php on line 33

 

I'm guessing it has to do with the quotes I have in there.

 

Any thoughts on how to fix this?

 

Thank you in advance!

Link to comment
https://forums.phpfreaks.com/topic/208856-searching-for-links-in-a-page/
Share on other sites

A * represents 0 or more characters matching the character preceding the *, in your case however the preceding character is an non-escaped bracket which is part of a capture group, therefore the * has 'nothing to repeat'. I will assume you are trying to capture URL of all anchor tags that have a href ending with register.php. On a side note your pattern is assumably missing delimiters, the only reason it hasn't thrown an error is the fact that the character at the start and end of your pattern, just happen to be valid delimiters.

 

preg_match_all('<a href="(.*?)register.php" class=l>',$html,$links);

 

 

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.