lihman Posted September 2, 2009 Share Posted September 2, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/172848-regex-with-curl-to-get-urls/ Share on other sites More sharing options...
Garethp Posted September 2, 2009 Share Posted September 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/172848-regex-with-curl-to-get-urls/#findComment-911007 Share on other sites More sharing options...
attock Posted September 3, 2009 Share Posted September 3, 2009 What would be the difference between preg_match_all('~ & preg_match_all('/ Quote Link to comment https://forums.phpfreaks.com/topic/172848-regex-with-curl-to-get-urls/#findComment-911772 Share on other sites More sharing options...
thebadbad Posted September 3, 2009 Share Posted September 3, 2009 See http://www.phpfreaks.com/forums/index.php/topic,265361.msg1251283.html#msg1251283 Quote Link to comment https://forums.phpfreaks.com/topic/172848-regex-with-curl-to-get-urls/#findComment-911788 Share on other sites More sharing options...
attock Posted September 3, 2009 Share Posted September 3, 2009 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/172848-regex-with-curl-to-get-urls/#findComment-911810 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.