Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Why doesn't this work?
- I have a simple file (symbols.dat) containing one stock
symbol per line.Example:
AMD
INTC
MSFT
AAPLI want to take the contents of that file, put it into an array
and turn it into a single string, separated by "+".Example:
$symbolfile = array("data/symbols.dat");
sort($symbolfile);
$symbols = implode('+', $symbolfile);The final result(string) should like:
AMD+MSFT+INTC+AAPL+
If I skip the file, and just declare the array in the actual
php script, everything works fine. When I try and pull it
from the file, nothing is returned... not even an error.I'm sure the proper permissions are in place and the file
definately exists. I tried opening the file in advance, using
fopen, though that didn't seem to make a difference
either.Any ideas? Thanks in advance.

correction, instead of:
$symbolfile = array("data/symbols.dat");
I'm using:
$symbolfile = file("data/symbols.dat");
Although, if I echo it out, it appears to work ok. It must be
a problem with another part of my script. I'm using the
string in a URLAgain, when I declare the entire array and its contents
within the script, it works fine.

I've managed a workaround by simply separating each symbol by commas, instead of new lines.
However, now it appears I've lost the ability to sort the array.

This was resolved over at phpfreaks.com.
It turns out that there was in fact a space between each symbol and "+" marker; I assume from the file.
ex.
AMD +IBM +SIRI +MSFT +DELL
The code below took care of it.
$arr = file('data/symbols.dat');
sort($arr);
foreach($arr as $k=>$v){
$arr[$k]=trim($v);
}
$sym = implode('+', $arr);

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |