Вопрос

Im trying to delete the slashes of a array output. I am using the .csv file from yahoo finance. Somehow i can't get it work, the slashes don't strip. The output i get is "Google .inc" with slashes.

<?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..
}
?>
Это было полезно?

Решение

Finally, i did it with str_replace.

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

Full:

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


  print_r($name);
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top