Jump to content

Regex with cURL to get URLS


lihman

Recommended Posts

I need to use regex with php/cURL. In order to explain what I need, I will use examples.

 

$url = "http://www.domain.com/list/";

^^Displays a table:

 

<table>

<tr>

<td>Name</td><td>Number</td>

</tr>

<tr>

<td><a href="name/10455/">Lihman</a></td><td>2,654</td>

</tr>

</table>

 

I need a regex function that will scan that table in the page and look for anything larger than 2,000 and then get the link from the Name column.

It then needs to take the second half of the link after the 'name/' part and keep the 10455/.

 

I then need to use those numbers to change the value of $url.

So it would then be:

$url = "http://www.domain.com/find/10455";

 

 

If that doesn't work somehow, the second alternative would be to write the name (in this case:'Lihman') to a txt file since the number beside it is larger than 2,000.

Link to comment
Share on other sites

This is a help section, not a "We'll do it for you" section. So as help, here are some links for you to look at

 

http://www.regular-expressions.info/

http://au.php.net/print_r

http://au.php.net/function.fopen

http://au.php.net/manual/en/function.fwrite.php

 

My suggestion would be something like

 

preg_match_all('~<td>(.+)</td><td>([0-9,]{5})</td>~',$input,$output);

 

And then running through the array and formatting the numbers

 

Though you could simplify that if you could make a regex to only see the number if it's above 2000. The only thing that gets me stuck is the , that is in it. Oh well, one of the other more talented guys here might know it

Link to comment
Share on other sites

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.