gdfhghjdfghgfhf Posted June 18, 2013 Share Posted June 18, 2013 i got a script that will look for a specific file on my server and then return a link to access the file. Problem is that if the search query includes parenthesis the script will not return anything. For example, if $search = "test(test)test[test].zip" the script will not return anything even if the file test(test)test[test].zip exist on the server how can i fix it ? header('Content-Type: text/html; charset=utf-8');$root = $_SERVER['DOCUMENT_ROOT']; $search = addslashes(utf8_decode($_GET['search']));function rsearch($folder, $pattern) { $dir = new RecursiveDirectoryIterator($folder); $ite = new RecursiveIteratorIterator($dir); $files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH); $fileList = array(); foreach($files as $file) { $fileList = array_merge($fileList, $file); } return $fileList;}$resultat = rsearch($root, '/.*\/'.$search.'/');//print_r($resultat);echo "<br>";echo utf8_encode($resultat[0]); Link to comment https://forums.phpfreaks.com/topic/279301-how-to-escape-parenthesis/ Share on other sites More sharing options...
doddsey_65 Posted June 18, 2013 Share Posted June 18, 2013 You will need to escape the parenthesis in your search query like so $search = "test\(test\)test\[test\]\.zip Link to comment https://forums.phpfreaks.com/topic/279301-how-to-escape-parenthesis/#findComment-1436565 Share on other sites More sharing options...
kicken Posted June 18, 2013 Share Posted June 18, 2013 Since you are putting the term into a regex, you'd need to escape any characters that are special to regex (unless you want the end-user to be able to use a regex). Have a look at preg_quote to solve the problem. Link to comment https://forums.phpfreaks.com/topic/279301-how-to-escape-parenthesis/#findComment-1436572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.