Re: Str_Replace Command
| From: | Matt Matijevich | Date: | Mon, 02 Feb 2004 17:24:45 +0000 |
| Subject: | Re: Str_Replace Command | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-176588@lists.php.net to get a copy of this message | ||
<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;