Jump to content

Question

Posted

I am trying to grab stock quotes from Yahoo Finance. I am completely new to regular expressions...

The stock price comes like this: [size=3][font=monospace]<span id="yfs_l84_$symbol">[color=#000000]price[/color][/font][font=monospace]</span>, where $symbol is the ticker symbol and price is something like 6.75 (no $ sign)[/font]

[font=monospace]This is what I have so far:[/font][/size]

[CODE]
$content = file_get_contents('http://finance.yahoo.com/q?s=$symbol');

preg_match('#<span id="yfs_184_$symbol">#', $content, $match);
$price = $match[1];

echo "Price: $price";
[/CODE]

I really have no idea what I'm doing with preg_match, and the PHP documentation didn't really help much. When I run this code, I get "error: Undefined Offset: 1," referring to $match[1].

What am I doing wrong?

Share this post


Link to post
Share on other sites

1 answer to this question

  • 0

Posted

Have you tried the CSV feed via YQL interface, it's pretty handy.

[url="http://y.ahoo.it/k34ae"]http://y.ahoo.it/k34ae[/url]

Note the REST [url="http://is.gd/WKTXYF"]link[/url] towards the bottom of the page.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.