help with loading arrays ...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rxsid
Forum Commoner
Posts: 82
Joined: Thu Aug 29, 2002 12:04 am

help with loading arrays ...

Post 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?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
rxsid
Forum Commoner
Posts: 82
Joined: Thu Aug 29, 2002 12:04 am

Post 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?
Post Reply