pmorrison Posted March 6, 2006 Share Posted March 6, 2006 Hi,I am trying to access a text file which contains a list of postcodes, each on a separate line. I want to go through this file, checking to see if the postcode entered is valid. I tried using it, but realised that it wasnt searching the file correctly. I have put in the line echo "$numLines"; to see how many lines it says are in the text file, it says there is only 1, but I know there are more. Am I trying to access the file incorrectly? I have put the list.txt file in the same directory as the php file.Cheers,Paul$filename = "/list.txt"; // File which holds all data$inputString = $postcode;$arrFp = file( $filename ); // Open the data file as an array$numLines = count( $arrFp ); // Count the elements in the array$numWords = count( $arrWords ); // Count the words in the stringfor($j=0; $j<$numLines; $j++) { echo "$numLines"; $outputstring = "not found"; if(strstr($inputString, trim( $arrFp[$j] ))) { $errorlist = errorlist('Please fill in the "Postcode" field with a valid postcode', $errorlist); $errorform = 1; $postcodestyle = ' ; color:red'; $outputstring = "found it"; } echo $outputString; // Echo the string replacing restricted words} } Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2006 Share Posted March 6, 2006 no need to put in the slash before the file if it is in the same directory. putting the slash in makes php go back to root.try that firstRay Quote Link to comment Share on other sites More sharing options...
pmorrison Posted March 6, 2006 Author Share Posted March 6, 2006 Hi Ray,I tried it without the / but it then doesnt load the page when I click on the submit button, I get a blank page with just the header. However, when I comment out the $arrFp = file( $filename ); line it loads Ok, but obviously doesnt look at the file.Paul Quote Link to comment Share on other sites More sharing options...
pmorrison Posted March 7, 2006 Author Share Posted March 7, 2006 I have been looking into using text files with PHP and I am wondering if I need some kind of delimiter to show PHP that it is a new line. Currently each postcode is on a separate line, but just separated using a usual return, no \n or any other delimiter. Could this be a problem?Paul Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.