0

I have some code here, but I can't get it working. Could someone help me?

$file_string = file_get_contents('URL');
$search = "<tr><th> <a href=''>Data_name</a></th><td>(.*)</td></tr>";
preg_match($search, $file_string, $title);
$title_out = $title[1];
echo $title_out;
m59
  • 43,214
  • 14
  • 119
  • 136
User
  • 13
  • 1
  • 4
  • 1
    [Please don't use Regexp to parse HTML](http://stackoverflow.com/a/1732454/1607098) Take a look at [DOM](http://php.net/dom) instead – Touki Dec 26 '12 at 15:42
  • 1
    What isn't working, is there an error? You are missing an `";` at the end of line 2 – Sharlike Dec 26 '12 at 15:42
  • If you must use Regex, please post examples of the data you're searching and some expected matches/non matches. – FrankieTheKneeMan Dec 26 '12 at 16:08
  • Can you show the html content of the page you trying to scrap data from ? –  Aug 22 '13 at 16:06

1 Answers1

0

Take a look at what @Touki said - but this may help you with any future regex problems you might have:

  1. You probably aren't looking at anything beyond the first line. You want to use "multiline"

  2. <tr><th> <a href=''>Data_name</a></th><td>(.*)</td></tr> seems to look at pretty exact string. Ensure your white space is correct (tabs, spaces, new lines etc). You also seem to be missing a hyperlink, not sure if that was intentional or not.

Duniyadnd
  • 4,013
  • 1
  • 22
  • 29