我试图删除数组输出的斜杠。我正在使用来自 yahoo Finance 的 .csv 文件。不知何故,我无法让它工作,斜线不会剥离。我得到的输出是带有斜杠的“Google .inc”。
<?php
// Setup Variables
$stockList = "goog";
$stockFormat = "snl1d1t1c1hgw";
$host = "http://quote.yahoo.com/d/quotes.csv";
$requestUrl = $host."?s=".$stockList."&f=".$stockFormat."&amp;amp;amp;e=.csv";
// Pull data (download CSV as file)
$filesize=2000;
$handle = fopen($requestUrl, "r");
$raw = fread($handle, $filesize);
fclose($handle);
// Split results, trim way the extra line break at the end
$quotes = explode("\n",trim($raw));
// Function to stripslashes from array
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
foreach($quotes as $quoteraw) {
$quoteraw = str_replace(", I", " I", $quoteraw);
$quote = explode(",", $quoteraw);
//Call function to strip the slashes
$quote = stripslashes_deep($quote);
//output second array, name of stock
echo $quote[1]; // This outputs "Google .Inc" with slashes..
}
?>