RE: [PHP] data from service into array
| From: | Craig Westerman | Date: | Thu, 07 Mar 2002 00:02:15 +0000 |
| Subject: | RE: [PHP] data from service into array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-87549@lists.php.net to get a copy of this message | ||
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 ><>
westerman@chanuteks.com
-----Original Message-----
From: Jim Winstead [mailto:jimw@apache.org]
Sent: Wednesday, March 06, 2002 4:23 PM
To: php-general@lists.php.net
Subject: Re: [PHP] data from service into array
Craig Westerman <westerman@chanuteks.com> 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