0

I have been trying to get specific table from other website. The code i used to get the page with curl can extract the entire page successfully. They have this table in their html code:

<table width="380" cellspacing="1" cellpadding="0" border="0" bgcolor="#cccccc" align="center">(...desired content...)</table>

Which is the only part i want from the entire page. Is there a proper way to get that?

I have been using:

if (preg_match('/<table width="380" cellspacing="1" cellpadding="0" border="0" bgcolor="#cccccc" align="center">(.*)<\/table/s', $response, $matches)) { echo $matches[0]; }

which returns no result. Thank you for the help.

user2002495
  • 2,126
  • 8
  • 31
  • 61
  • [It works](http://regex101.com/r/fY8iL3). Make sure to check the **source code** in the browser. Also you might use an ungreedy pattern by using `.*?` instead of `.*`. Ultimately you should be using a proper HTML/DOM parser. – HamZa Aug 14 '13 at 08:43
  • Ah I think you need to use `$matches[1]`. For testing purposes I always tend to print the whole array `print_r($matches);` or `var_dump($matches);` – HamZa Aug 14 '13 at 08:45
  • Like @HamZa already mentioned, regular expresion is not o.k. for html parsing. Read this > http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php/3577662#3577662 – Glavić Aug 14 '13 at 08:46
  • is php-curl module installed – Rudra Aug 14 '13 at 08:48
  • it is installed, i already mentioned i can get the entire page. I just need that specific part. – user2002495 Aug 14 '13 at 08:49
  • it's still not working, as if the matches does not match anything. If anyone interested the page i'm trying to get is: http://www.bi.go.id/web/id/Moneter/Kurs+Bank+Indonesia/Kurs+Transaksi/ and the table im trying to get is the main big one on the middle of the page. – user2002495 Aug 14 '13 at 08:53
  • @user2002495 Please use your logic. Open the source and check what you have. You will quickly notice that the position of the attributes are not in the same place. Regex is about regular strings, it won't "think" for you "ah ! that's an attribute let's check it out whether it's at the beginning or the end". If you have trouble with such a simple case then I don't recommend regex for you and advice you to use an HTML parser. – HamZa Aug 14 '13 at 08:58

0 Answers0