I am trying to do a very simple list explode using spaces as the delimiters. However, I am have some problems with the following string…
“+0.59 – +0.58%” “+0.06 – +0.14%” “-0.47 – -1.07%” “-0.77 – -0.20%” //Input
And the resultant array which is supposed to be separated by each space (quotes also removed)
Array ( [0] => +0.59 [1] => – [2] => +0.58% +0.06 [3] => – [4] => +0.14% -0.47 [5] => – [6] => -1.07% -0.77 [7] => – [8] => -0.20% )
Basically the spaces aren’t being recognized correctly. I have already tried separating it via /n /r and ‘/\s*/m’.
Here is a snippet of my code.
$open = fopen("http://finance.yahoo.com/d/quotes.csv?s=$ticker&f=c&e=.csv", "r");
$quote = fread($open, 2000);
fclose($open);
$quote = explode(" ", $quote);
foreach ($quote as &$value) {
$value = str_replace('"',"",$value);
}
//print_r($tickerlist);
print_r($quote);
Open a file in a proper editor (vim would be nice for this. maybe notepad++) and check for
tabcharacter and\rand\n.