PHP:Yahoo的Stripslashes资助.CSV数组

时间:2013-04-12 09:57:10

标签: php arrays csv finance stripslashes

我试图删除数组输出的斜杠。我正在使用雅虎财经的.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;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..
}
?>

1 个答案:

答案 0 :(得分:0)

最后,我用str_replace做了。

$name = str_replace("\"", "", $quote[1]);

全:

foreach($quotes as $quoteraw) {
  $quoteraw = str_replace(", I", " I", $quoteraw);
  $quote = explode(",", $quoteraw);
  $name = str_replace("\"", "", $quote[1]);


  print_r($name);
}