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
https://forums.phpfreaks.com/topic/172848-regex-with-curl-to-get-urls/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.