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
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);

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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