Jump to content

In this example how does $quote get assigned it's value?


Recommended Posts

In the example below I see how $pattern and $contents get assigned a value.  But I don't see where $quote gets it's value.  I'm guessing I don't fully understand the eregi() function.  Could someone dumb this down for me into a real world example?

 

Thanks.

 

 

 

<?php

  // choose stock to look at

  $symbol='AMZN';

  echo "<h1>Stock Quote for $symbol</h1>";

 

  $theurl="http://www.amex.com/equities/listCmp/EqLCDetQuote.jsp?Product_Symbol=$symbol";

 

  if (!($contents = file_get_contents($theurl)))

  {

    echo 'Could not open URL';

    exit;

  }

 

  // find the part of the page we want and output it

  $pattern = '(\\$[0-9 ]+\\.[0-9]+)';

 

  if (eregi($pattern, $contents, $quote))

  {

    echo "<p>$symbol was last sold at: ";

    echo $quote[1];

    echo '</p>';

  }

  else

  {

    echo '<p>No quote available</p>';

  };

 

 

  // acknowledge source

  echo '<p>'

      .'This information retrieved from <br />'

      ."<a href=\"$theurl\">$theurl</a><br />"

      .'on '.(date('l jS F Y g:i a T')).'</p>';

?>

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.