RE: [PHP] Str_Replace Command
| From: | Crane, Christopher | Date: | Mon, 02 Feb 2004 17:35:04 +0000 |
| Subject: | RE: [PHP] Str_Replace Command | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-176591@lists.php.net to get a copy of this message | ||
Matt:
This worked perfect. Thank you. I didn't realize it was reassigning, I
thought it would work similar to array_push and add to the existing data. I
get it now, thanks to you.
Thanks again. I had been so frustrated I was losing my objectivity.
Christopher J. Crane
Network Manager - Infrastructure Services
IKON Document Efficiency at Work
-----Original Message-----
From: Matt Matijevich [mailto:matijevich@alliancetechnologies.net]
Sent: Monday, February 02, 2004 12:25 PM
To: ccrane@ikon.com; php-general@lists.php.net
Subject: Re: [PHP] Str_Replace Command
<snip>
$StockURL =
"http://finance.yahoo.com/d/quotes.txt?s=xrx,ikn,danky&f=sl1&e=.txt";
$StockResults = implode('', file("$StockURL"));
$Rows = split("\n", $StockResults);
foreach($Rows as $Row) {
list($Symbol, $Price) = split(",", $Row); $Symbol = str_replace('"',
"", $Symbol);
echo $Symbol." - ".$Price."<br>\n";
$TickerData = array ($Symbol => $Price);
}
print_r($TickerData);
</snip>
why not replace:
$TickerData = array ($Symbol => $Price);
that line reassigns $TickerData to a array with one element in it everytime
you call it. The last time through your loop, $Symbol = ''
and $Price = '', so you get Array ( [] => ) when you print_r
with this:
$TickerData[$Symbol] = $Price;