Jump to content

how to escape parenthesis ?


Go to solution Solved by kicken,

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.