Jump to content

how to escape parenthesis ?


gdfhghjdfghgfhf

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.