Canadian Posted December 12, 2009 Share Posted December 12, 2009 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/184901-in-this-example-how-does-quote-get-assigned-its-value/ Share on other sites More sharing options...
wildteen88 Posted December 12, 2009 Share Posted December 12, 2009 $quote will contain an array of matches. All is explain in the manual for eregi. Quote Link to comment https://forums.phpfreaks.com/topic/184901-in-this-example-how-does-quote-get-assigned-its-value/#findComment-976089 Share on other sites More sharing options...
Canadian Posted December 12, 2009 Author Share Posted December 12, 2009 Thanks wildteen88. I got it now. Quote Link to comment https://forums.phpfreaks.com/topic/184901-in-this-example-how-does-quote-get-assigned-its-value/#findComment-976094 Share on other sites More sharing options...
cags Posted December 13, 2009 Share Posted December 13, 2009 Perhaps just worth noting that you should probably look at using the preg_ functions such as preg_match as eregi is deprecated and will be removed as of PHP 6.0. Quote Link to comment https://forums.phpfreaks.com/topic/184901-in-this-example-how-does-quote-get-assigned-its-value/#findComment-976468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.