Page 1 of 1

help with loading arrays ...

Posted: Fri Nov 15, 2002 1:46 pm
by rxsid
all,

When I try to load an array with a string that contains spaces, this doesn't work:

Code: Select all

$something = array ("apple", "orange", "green bananas", "very hot chilies");

$fp = fopen("test.txt", "r");
$contents = fread($fp, 4096);
fclose($fp);

$testInfo = explode("\n",$contents);

$linecnt = count($testInfo);

for ($cnt=40; $cnt < $linecnt;$cnt++) {
  foreach($something as $val) {
    if (stristr($testInfoї$cnt],$val)) {
        echo $testInfoї$cnt];
    }
  }
}
green bananas & very hot chilies don't show up properly.

any help?

Posted: Fri Nov 15, 2002 1:58 pm
by BDKR
Are you sure it's the array? When I did this

Code: Select all

$something = array ("apple", "orange", "green bananas", "very hot chilies");

foreach($something as $val) 
  { echo "$val\n";  }
I see all the elements of the array just fine.

Cheers,
BDKR

Posted: Fri Nov 15, 2002 2:19 pm
by rxsid
the values are in the file,
very strange though...
when i create a file with those elements & others...the correct ones are displayed, but when I open a url (instead of a text file on my server) and search for those elements that I can see on the url...only the the word up to space & not after is displayed.

wierd eh?