Fix this code please. the error is, its not unset() JoJo
~here.txt~ Ace JoJo John
<?php $file = file("here.txt"); $c = count($file); for($n=0;$n<$c;$n++){ if($file[$n]=="JoJo"){ unset($file[$n]);}else{ echo $file[$n]."<BR>";}} echo $c; ?>
When i run the script, all it does echo only.
its show me this
Ace JoJo John 3
it seem like its skiping unset().
so far all i kno that if i remove the if statment it will work.
but i need the if statment to do what i have planed.
view source on your output'd page, I bet each line is on a seperate line in the html output
most likely, "JoJo" isnt matching because what you are getting from the file(); is "JoJo\n"
just a guess... but I seem to recall all file functions returning EOL also
nothing...
just for double checking
echo nl2br($file[$n]);
but, do u see what i'm trying to do? is there any other way?
testing it now, and yes
<?php $file = file("here.txt"); $c = count($file); for($n=0;$n<$c;$n++) { $file[$n] = trim($file[$n]); //strip any whitespace chars if($file[$n]=="JoJo"){ unset($file[$n]); } else { echo $file[$n]."<BR>"; } } echo $c; ?>
I was right, it was extra ctrl codes from the file read for carriage return line feed interefereing with the if check, trim() removes them
i think, it might have something to do what the if statment. but i dont see why it is the cuase. thanks for helping me
oh, thanks you!, it works. but what was the problem?
i see, thanks