masterens Posted April 11, 2010 Share Posted April 11, 2010 Hello, First: I am new to PHPFreaks. This is my first post and it's complicated. I hope someone can help me. I am creating a search system without SQL, because SQL seems not to respond on my server. It is a search for people. Users make their own profile with all their information stored in two files in the main directory of my server. If I put it in folders, the right to write and read is gone.(? Another server problem ?) Everything in folders is 403 Forbidden. All users get two files: ___username.log and ___username_.log ___username.log contains information that was filled in in a form, each details is on another line. ___username_.log contains the description of the person, entered by himself. This can be multiple lines, so this is another file. The only HTML file on my server is the home file, which starts with an IFRAME with home.php search.php should store all filenames in the folder starting with ___ in an array, and then search all files for the search query. All files ending with _.log should be called after the normal .log, so the searcher doesn't get two persons below each other. All files that do not contain all searched words, should be removed from the array. Does anyone know how to do this? Thanks already, Masterens PS: If I made languagemistakes, sorry, I am not English/American PS2: This is my search.php for now. I realised that it is not going to work: <?php if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "$file\n"; } else { echo 'Er ging iets fout bij het zoeken'; } } closedir($handle); } else { echo 'Er ging iets fout bij het opvragen van details bij de database'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198190-store-all-filenames-starting-with-___-and-ending-with-log-from-folder-in-array/ Share on other sites More sharing options...
oni-kun Posted April 11, 2010 Share Posted April 11, 2010 glob supports wild cards and file matching patterns, You'll find it simple to implement. The following code may not work without tweeking, but it seems simple: $username = glob($path.'___*.log'); $userinfo = glob($path.'___*_.log'); You can append array searches to $username and $userinfo arrays for your keyword exclusions. Quote Link to comment https://forums.phpfreaks.com/topic/198190-store-all-filenames-starting-with-___-and-ending-with-log-from-folder-in-array/#findComment-1039870 Share on other sites More sharing options...
masterens Posted April 11, 2010 Author Share Posted April 11, 2010 Thank you, oni-kun, I will look at it soon. I have this for now <?php if ($handle = opendir('')) { echo "Zoekresultaten:\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { echo "$file\n"; } $numboffiles=count($file) $fileshad=0; while ($fileshad <= $numboffiles) { $check=0; $check=substr_count($file[$fileshad],"___"); if ($check >= 1) { $userfiles[$fileshad] = $file[$fileshad]; } $fileshad++ } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198190-store-all-filenames-starting-with-___-and-ending-with-log-from-folder-in-array/#findComment-1039872 Share on other sites More sharing options...
oni-kun Posted April 11, 2010 Share Posted April 11, 2010 The function I mentioned can replace every line of your code for you. Quote Link to comment https://forums.phpfreaks.com/topic/198190-store-all-filenames-starting-with-___-and-ending-with-log-from-folder-in-array/#findComment-1039874 Share on other sites More sharing options...
masterens Posted April 11, 2010 Author Share Posted April 11, 2010 The function I mentioned can replace every line of your code for you. ok, thank you. I will try to understand Quote Link to comment https://forums.phpfreaks.com/topic/198190-store-all-filenames-starting-with-___-and-ending-with-log-from-folder-in-array/#findComment-1039875 Share on other sites More sharing options...
masterens Posted April 17, 2010 Author Share Posted April 17, 2010 but wouldnt the first line with glob also find the second line? i mean * can be $path."example".'.log' * can also be $path."example_".'.log' the first line would also find the second or can I just do something like $username -= $userinfo Quote Link to comment https://forums.phpfreaks.com/topic/198190-store-all-filenames-starting-with-___-and-ending-with-log-from-folder-in-array/#findComment-1043620 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.