Jump to content

Better way other than pregmatch?


lawrenceboland

Recommended Posts

I'm trying to extract information out of certain sites such as http://finance.yahoo.com/q/ae?s=TG

 

If I am trying to get specific rows of information out of here (or even all of it), is there an easier way that trying to preg_match my way from html tag to html tag?

 

I'm a php newb.. you don't need to give me all the code, I know thats annoying.  I'd just like to know if theres an easier way, and what functions I should use.

 

I'm getting along in my coding, but its slow going trying to preg_match tag by tag.

 

-Bo

Link to comment
https://forums.phpfreaks.com/topic/64035-better-way-other-than-pregmatch/
Share on other sites

I would use stripos and substr.

As long as the data are stored in the simple table...

  $contentofsite = '<html.....</html>';

  function GetCont($search, $htmldata) {
    $_table_start = ($i = stripos($htmldata, '<td><b>'.$search)) !== false ? stripos($htmldata, '<table', $i-100) : -1;
    if ($_table_start > 0) 
      return ($i = stripos($htmldata, '</table>', $i+6)) !== false ? substr($htmldata, $_table_start, $i-$_table_start+ : 'Not found';

    return 'Not found';
  }
  
  echo GetCont('Earnings Est', $contentofsite);

  • 2 weeks later...

Are you only trying to get stock prices, volume, etc?

Yahoo provides an API (well, kinda) to do this rather easily. I have not done this myself but have seen it done and know tutorials exist to do it. Friend of mine wrote a trading simulator in VB using info from finance.yahoo.com (I'm 95% sure of this anyway), I don't think there was HTML parsing of any kind.

 

I'm thinking it returned comma separated values...

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.