nick1 Posted May 2, 2006 Share Posted May 2, 2006 Greetings,I'm aware PHP can read the entire contents of a file into a string then from there it's possible to search that string for some data.And I'm also aware that PHP can read the entire contents of a file into an array then from there it's possible to search that array for some data.But can PHP search a file (such as a .txt or .html file) for a string of data?If not, then I guess I'm stuck with the first two options I listed. In that case, lets say I have a .txt file with a bunch of text in it. I want to locate a specific phrase within that text file. Is it more efficient (faster results) to read the contents of that .txt file into a string or an array? Then perform the search.Thanks in advance,*Nick* Quote Link to comment Share on other sites More sharing options...
ober Posted May 2, 2006 Share Posted May 2, 2006 Well, the way to search a file for a string is to read it into either a string or an array and search those. As for the most efficient, if you're just looking for a specific string in the entire file, I'd suggest just reading it all into one string. In 98% of all other cases, I'd suggest reading it into an array. You can just as easily search the array as well. 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.