Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 280485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:07:21+00:00 2026-05-12T05:07:21+00:00

I have the following function to return a clean path for a script. function

  • 0

I have the following function to return a clean path for a script.

function cleanPath($path) {
        $path = (string) $path;
        $path = preg_replace(
            array(
            '#[\n\r\t\0]*#im',
            '#/(\.){1,}/#i',
            '#(\.){2,}#i',
            '#(\.){2,}#i',
            '#('.DIRECTORY_SEPARATOR.'){2,}#i'
            ),
            array(
            '',
            '',
            '',
            '/'
            ),
            $path
            )
        ;
        return rtrim($path,DIRECTORY_SEPARATOR);
    }

PHP gives the error:

Warning: preg_replace() [function.preg-replace]: Compilation
failed: missing ) at offset 7 in C:\wamp\www\extlogin\app\ni\inc\classes\cfiletree.php on line
18

Any ideas about what’s wrong and how to fix it?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:07:21+00:00Added an answer on May 12, 2026 at 5:07 am

    Most likely DIRECTORY_SEPARATOR is \ which means it’ll escape the ) rather than match a backslash. You need to escape DIRECTORY_SEPARATOR so that it becomes \\ in the regex.

    The safest way to escape strings placed in regular expressions is to use preg_quote:

    preg_quote(DIRECTORY_SEPARATOR, '#');
    

    The second argument, '#', is the separator you use for your regular expression, which in your case is #.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following repository: public function findClassPhotoByPath($path) { return $this->getEntityManager() ->createQuery('SELECT p FROM KSRGalleryBundle:Photo
I have the following code <div class=framepage> <header> <script type=text/javascript> function getBaseUrl() { return
have the following function on my collection : getFiltered: function (status, city) { return
I have the following code: pub.call_response = function() { return { units: [ {
In python I have the following function: def is_a_nice_element(element, parameter): #do something return True
I have the following code: use strict; function isDefined(variable) { return (typeof (window[variable]) ===
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
I have the following code $(document).ready(function() { $('a#slick-toggle').click(function() { $('#slickbox0').toggle(400); return false; }); });
I have the following javascript: $('#ge-display').click(function (event) { window.open('/googleearth/ge-display.php','','scrollbars=yes,menubar=no,height=650,width=1000,resizable=yes,toolbar=yes,location=no,status=no'); event.stopPropagation(); return false; }); the
I have the following code: $('.tagform').submit(function() { $('#tagsubmit-???').toggle('1000'); return false; }); And I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.