RE: [PHP] Retrieving data from a URL in PHP

2002-06-05 Thread Vail, Warren

Yahoo keeps moving things around.  I had the same result with a news feed.

If you research the page at

http://finance.yahoo.com/?u

you should be able to figure out how they get quotes.

good luck,

Warren Vail
Tools, Metrics  Quality Processes
(415) 667-7814
Pager (877) 774-9891
215 Fremont 02-658


-Original Message-
From: Anthony Ritter [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 1:11 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Retrieving data from a URL in PHP


The code that follows is from Welling and Thomson's book on PHP and mysql
(page 372)

I've tried it on Apache/ MS Windows 98 / PHP and I get the following line:

No quote available.

Questions...

1. Why can't I retrieve the present stock quote?

2. What is the variable
$quote

represent in the script?

I cannot find where $quote has been assigned.

Thanking all in advance.
Tony Ritter
..


html
head
titleStock Quote from NYSE/title
/head
body
?
$symbol=IBM;
echo h1Stock Quote for $symbol/h1;
$theurl=http://finance.yahoo.com/q?s=ibmd=v1;;
if (!($fp=fopen($theurl, r)))
 {
  echo Could not open the URL;
  exit;
 }
$contents= fread($fp, 100);
fclose($fp);
$pattern=(\\\$[0-9]+\\.[0-9]+);
if (eregi($pattern,$contents,$quote))
 {
  echo $symbol was sold at:  ;
  echo $quote[1];
 }
else
 {
  echo No quote available.;
 }
echo br.This information retrieved frombr.a
href=\$theurl\$theurl/abr.on .(date(l jS F Y g:i a T));
?
/body
/html





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Retrieving data from a URL in PHP

2002-06-05 Thread Analysis Solutions

Try
  $content = implode('', file(URL...) );

rather than the fopen(), file pointer route.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Retrieving data from a URL in PHP

2002-06-05 Thread Austin Gonyou

You may need a user:pass appended to the URI.

On Wed, 2002-06-05 at 15:11, Anthony Ritter wrote:
 The code that follows is from Welling and Thomson's book on PHP and
 mysql
 (page 372)
 
 I've tried it on Apache/ MS Windows 98 / PHP and I get the following
 line:
 
 No quote available.
 
 Questions...
 
 1. Why can't I retrieve the present stock quote?
 
 2. What is the variable
 $quote
 
 represent in the script?
 
 I cannot find where $quote has been assigned.
 
 Thanking all in advance.
 Tony Ritter
 ..
 
 
 html
 head
 titleStock Quote from NYSE/title
 /head
 body
 ?
 $symbol=IBM;
 echo h1Stock Quote for $symbol/h1;
 $theurl=http://finance.yahoo.com/q?s=ibmd=v1;;
 if (!($fp=fopen($theurl, r)))
  {
   echo Could not open the URL;
   exit;
  }
 $contents= fread($fp, 100);
 fclose($fp);
 $pattern=(\\\$[0-9]+\\.[0-9]+);
 if (eregi($pattern,$contents,$quote))
  {
   echo $symbol was sold at:  ;
   echo $quote[1];
  }
 else
  {
   echo No quote available.;
  }
 echo br.This information retrieved frombr.a
 href=\$theurl\$theurl/abr.on .(date(l jS F Y g:i a T));
 ?
 /body
 /html
 
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
-- 
Austin Gonyou
Systems Architect, CCNA
Coremetrics, Inc.
Phone: 512-698-7250
email: [EMAIL PROTECTED]

One ought never to turn one's back on a threatened danger and 
try to run away from it. If you do that, you will double the danger. 
But if you meet it promptly and without flinching, you will 
reduce the danger by half.
Sir Winston Churchill



signature.asc
Description: This is a digitally signed message part


RE: [PHP] Retrieving data from a URL in PHP

2002-06-05 Thread Scott Hurring

To illustrate what's wrong with the code from the book,
the following code works... notice what's different.

But really, you should've just loaded the URL and noticed
there's no $[0-9].[0-9] and instead it was bold.
problem solved.


$symbol=ibm;
echo h1Stock Quote for $symbol/h1\n;
$theurl=http://finance.yahoo.com/q?s={$symbol}d=v1;;
if (!($fp=fopen($theurl, r)))
 {
  echo Could not open the URL;
  exit;
 }
$contents= fread($fp, 100);
fclose($fp);

if (preg_match(/(b[0-9]+\.[0-9]+\/b)/,$contents, $quote))
 {
  echo $symbol was sold at:  ;
  echo $quote[1];
 }
else
 {
  echo No quote available.;
 }

echo br.This information retrieved frombr.a
href=\$theurl\$theurl/abr.on .(date(l jS F Y g:i a T));


---
Scott Hurring
Systems Programmer
EAC Corporation
[EMAIL PROTECTED]
Voice: 201-462-2149
Fax: 201-288-1515

 -Original Message-
 From: Anthony Ritter [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, June 05, 2002 4:53 PM
 Subject: [PHP] Retrieving data from a URL in PHP
 
 The code that follows is from Welling and Thomson's book on 
 PHP and mysql
 (page 372)
 
 I've tried it on Apache/ MS Windows 98 / PHP and I get the 
 following line:
 
 No quote available.
 
 My questions...
 
 1. Why can't I retrieve the present stock quote?
 
 and
 
 2. What does the variable
 
 $quote
 
 represent in the script?
 
 I cannot find what the variable -or array - $quote has been 
 assigned to.
 Please see:
 
 echo $quote[1];
 
 below
 
 Thanking all in advance.
 Tony Ritter
 ..
 
 
 html
 head
 titleStock Quote from NYSE/title
 /head
 body
 ?
 $symbol=IBM;
 echo h1Stock Quote for $symbol/h1;
 $theurl=http://finance.yahoo.com/q?s=ibmd=v1;;
 if (!($fp=fopen($theurl, r)))
  {
   echo Could not open the URL;
   exit;
  }
 $contents= fread($fp, 100);
 fclose($fp);
 $pattern=(\\\$[0-9]+\\.[0-9]+);
 if (eregi($pattern,$contents,$quote))
  {
   echo $symbol was sold at:  ;
   echo $quote[1];
  }
 else
  {
   echo No quote available.;
  }
 echo br.This information retrieved frombr.a
 href=\$theurl\$theurl/abr.on .(date(l jS F Y g:i a T));
 ?
 /body
 /html
 
 
 
 
 
 
 
 -- 
 PHP Windows Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php