jacko310592 Posted November 28, 2009 Share Posted November 28, 2009 hey everyone <?php $galleryDir = ''; foreach(glob("*", GLOB_ONLYDIR) as $dir) $galleryDir .= "$dir\n"; $strArr = explode("?", $_SERVER["REQUEST_URI"]); $thisDirectory = $strArr[sizeof($strArr) - 1]; $pageCorrect = strpos($galleryDir, $thisDirectory); if ($pageCorrect === false) { header('Location: ./index.php'); exit (0); } ?> as you see with the above code, on this line: "$pageCorrect = strpos($galleryDir, $thisDirectory);" it is looking for any charachters within $thisDirectory which are the same as those within the $galleryDir string, but is there a way to make it so not only do the charachers have to be the same, but it has to be the full word? within the string, there are several values, each of the single worded values need to be separate though, so im looking to change to code so it will look for full words which are the same, not single characters, nor the entire string. can anyone suggest a way this can be done thanks guys Link to comment https://forums.phpfreaks.com/topic/183175-compare-strings-for-full-words/ Share on other sites More sharing options...
Alex Posted November 28, 2009 Share Posted November 28, 2009 This can be done using PCRE functions, in particular preg_match, and the \b modifier, however in your case I'd opt for another option. It would be better to just store glob("*", GLOB_ONLYDIR) as a variable, to get a string ($galleryDir) from that you can get $galleryDir by implode(...). You can then use in_array to check if the directory exists. Another option would be to use file_exists, this would be better if you don't actually need the list of directories for any other processing. <?php $dirs = glob("*", GLOB_ONLYDIR); $galleryDir = implode("\n", $dirs); $strArr = explode("?", $_SERVER["REQUEST_URI"]); $thisDirectory = $strArr[sizeof($strArr) - 1]; if (!in_array($thisDirectory, $dirs)) { header('Location: ./index.php'); exit (0); } ?> Link to comment https://forums.phpfreaks.com/topic/183175-compare-strings-for-full-words/#findComment-966712 Share on other sites More sharing options...
jacko310592 Posted November 28, 2009 Author Share Posted November 28, 2009 thank you so much Alex, second time youve helped me today (: Link to comment https://forums.phpfreaks.com/topic/183175-compare-strings-for-full-words/#findComment-966713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.