RE: [PHP] data from service into array
Is anything hindering you from using XML expat? You can use that to do it. I already post a mail on this, search in the archive for xml related posts. *** This is data from a data service. This is the ENTIRE source code of the URL they let me receive: symbolRHAT/symbol price6.82/price date3/4/2002/date time3:59pm/time change0.32/change change_percent/change_percent open6.59/open high6.99/high low6.53/low volume932400/volume I'm just now trying to learn PHP. I don't know ANYTHING about XML. I don't even have any XML reference books yet. I did create a PHP script that is usable (see below), but there has to be a more efficient way to do it with PHP. I'll hunt up your post on XML in the archives after I get a XML book. Thanks Craig [EMAIL PROTECTED] ? $symbol = RHAT; $url = http://www.PAIDDATAPROVIDER.com/services/quote.cgi?quote=.$symbol; if (!($fp = fopen($url, r))) { echo Could not open URL; exit; } $rawdata = fread($fp, 1); fclose($fp); $pricepattern = (price(.*)/price); if (eregi($pricepattern, $rawdata, $price)) $datepattern = (date(.*)/date); if (eregi($datepattern, $rawdata, $date)) $timepattern = (time(.*)/time); if (eregi($timepattern, $rawdata, $time)) $changepattern = (change(.*)/change); if (eregi($changepattern, $rawdata, $change)) $openpattern = (open(.*)/open); if (eregi($openpattern, $rawdata, $open)) $highpattern = (high(.*)/high); if (eregi($highpattern, $rawdata, $high)) $lowpattern = (low(.*)/low); if (eregi($lowpattern, $rawdata, $low)) $volumepattern = (volume(.*)/volume); if (eregi($volumepattern, $rawdata, $volume)) ? On Tue, 5 Mar 2002, Craig Westerman wrote: I'm retrieving data from a data service. This is the ENTIRE source code of the URL they let me receive: symbolRHAT/symbol price6.82/price date3/4/2002/date time3:59pm/time change0.32/change change_percent/change_percent open6.59/open high6.99/high low6.53/low volume932400/volume How can I insert the data values into an array ? Thanks Craig [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php [EMAIL PROTECTED] --- We must use time wisely and forever realize that the time is always ripe to do right. -- Nelson Mandela --- -- 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] data from service into array
Craig Westerman [EMAIL PROTECTED] wrote: I'm just now trying to learn PHP. I don't know ANYTHING about XML. I don't even have any XML reference books yet. I did create a PHP script that is usable (see below), but there has to be a more efficient way to do it with PHP. I'll hunt up your post on XML in the archives after I get a XML book. the example you provided isn't xml. (it has some resemblance, but it isn't xml.) here's a code snippet that will turn that format into an array: $fp = fopen($url,r); if (!$fp) die(could not open URL); $out = array(); while (!feof($fp)) { $line = fgets($fp,512); if (preg_match('!(\w+?)(.*?)/\1!', $line, $m)) { $out[$m[1]] = $m[2]; } } fclose($fp); print_r($out); jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] data from service into array
Thanks Jim. Works like a charm. Real sweet. Would you explain what this line does? $out[$m[1]] = $m[2]; Learning is a real blast. Wish I would have jumped in a couple of years ago. Thanks again. Craig [EMAIL PROTECTED] -Original Message- From: Jim Winstead [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 06, 2002 4:23 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] data from service into array Craig Westerman [EMAIL PROTECTED] wrote: I'm just now trying to learn PHP. I don't know ANYTHING about XML. I don't even have any XML reference books yet. I did create a PHP script that is usable (see below), but there has to be a more efficient way to do it with PHP. I'll hunt up your post on XML in the archives after I get a XML book. the example you provided isn't xml. (it has some resemblance, but it isn't xml.) here's a code snippet that will turn that format into an array: $fp = fopen($url,r); if (!$fp) die(could not open URL); $out = array(); while (!feof($fp)) { $line = fgets($fp,512); if (preg_match('!(\w+?)(.*?)/\1!', $line, $m)) { $out[$m[1]] = $m[2]; } } fclose($fp); print_r($out); jim -- 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] data from service into array
On Wed, Mar 06, 2002 at 06:02:15PM -0600, Craig Westerman wrote: Would you explain what this line does? $out[$m[1]] = $m[2]; it assigns an entry to the output array. $m is populated by preg_match (where it was passed as the third argument) with the entire match in $m[0], the first parenthesized expression in $m[1] (which is the element name), and the second parenthesized expression in $m[2] (which is the value). jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] data from service into array
I'm retrieving data from a data service. This is the ENTIRE source code of the URL they let me receive: symbolRHAT/symbol price6.82/price date3/4/2002/date time3:59pm/time change0.32/change change_percent/change_percent open6.59/open high6.99/high low6.53/low volume932400/volume How can I insert the data values into an array ? Thanks Craig [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] data from service into array
Is anything hindering you from using XML expat? You can use that to do it. I already post a mail on this, search in the archive for xml related posts. On Tue, 5 Mar 2002, Craig Westerman wrote: I'm retrieving data from a data service. This is the ENTIRE source code of the URL they let me receive: symbolRHAT/symbol price6.82/price date3/4/2002/date time3:59pm/time change0.32/change change_percent/change_percent open6.59/open high6.99/high low6.53/low volume932400/volume How can I insert the data values into an array ? Thanks Craig [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php [EMAIL PROTECTED] --- We must use time wisely and forever realize that the time is always ripe to do right. -- Nelson Mandela --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php