Re: [PHP] data from service into array

2002-03-06 Thread Jim Winstead

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




RE: [PHP] data from service into array

2002-03-06 Thread Craig Westerman

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+?)>(.*?)!', $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

2002-03-06 Thread Jim Winstead

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+?)>(.*?)!', $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

2002-03-06 Thread Craig Westerman

>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:

RHAT
6.82
3/4/2002
3:59pm
0.32

6.59
6.99
6.53
932400

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]


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 = "((.*))";
  if (eregi($pricepattern, $rawdata, $price))

$datepattern = "((.*))";
  if (eregi($datepattern, $rawdata, $date))

$timepattern = "((.*))";
  if (eregi($timepattern, $rawdata, $time))

$changepattern = "((.*))";
  if (eregi($changepattern, $rawdata, $change))

$openpattern = "((.*))";
  if (eregi($openpattern, $rawdata, $open))

$highpattern = "((.*))";
  if (eregi($highpattern, $rawdata, $high))

$lowpattern = "((.*))";
  if (eregi($lowpattern, $rawdata, $low))

$volumepattern = "((.*))";
  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:
>
>
> RHAT
> 6.82
> 3/4/2002
> 3:59pm
> 0.32
> 
> 6.59
> 6.99
> 6.53
> 932400
>
>
> 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

2002-03-05 Thread S.Murali Krishna


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:
> 
> 
> RHAT
> 6.82
> 3/4/2002
> 3:59pm
> 0.32
> 
> 6.59
> 6.99
> 6.53
> 932400
> 
> 
> 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