[solved] reading from text file

I’m doing some simple code that doesn’t seem to be performing as expected. I am passing a single variable ‘page’ via the URL. The form is reading it, and looking into a text file. The code is taking each line of the text file and splitting it into 2 pieces, $pageName and $pageURL. I’m trying to set the variable $subject = $pageName if $page matches $pageURL. What is happening is that $subject is being set to the LAST line of the text file, no matter what $page is. I was focusing on the If statement nested within the foreach statement below, but cannot see anything wrong.

Here is the code.

if (isset($page)){
foreach($arr as $str) {
echo $pageName.", “.$pageURL.”


} [/code]
I know the text file is being read correctly because of the line echo $pageName.", ".$pageURL."<br/>"; I just put that in there to test it and will take it out once things are working. I know the page variable is being passed as well because I can echo that onto the screen.

Here is a sampling of the text file.

RW Cut-To-Length & Insulation Stripping Machine|rw
Coil Spreaders - Coil Formers|cf
Coil Winding Machines|cwm
TTT Tractor Drive Turn Taper|ttm

Any help would be appreciated.


that assigns $page to $pageURL and checks the assigned value (a string converted to bool). its always true.


compares two values.

when I change that, my subject2 variable doesn’t get assigned. It’s just blank.

thats because file is including the linefeed.

use trim

OK So trim tells me that it will take out the line feeds. I changed the subject line to


but that didn’t seem to help. It’s still blank.??

as the if is causing the problem and as the linefeed is at the end of the line (after $pageURL), i thought i wount have to mention to use trim($pageURL)


that did it. Thanks for the help.

Sponsor our Newsletter | Privacy Policy | Terms of Service