SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Warning: preg_replace(): No ending delimiter '~' found

    I get a warning on index.php page....

    Warning: preg_replace(): No ending delimiter '~' found in C:\xampp\htdocs\index.php on line 107

    PHP Code:
    /*
    *
    *
    */
    function parse_uri( )
    {
        
    // Removes any subfolders in which the app is installed
        
    $real_uri preg_replace('~^'.APP_FOLDER.'~'''$_SERVER['REQUEST_URI'], 1);

        
    $uri_array explode('/'$real_uri);

        
    // If the first element is empty, get rid of it
        
    if (empty($uri_array[0])) {
            
    array_shift($uri_array);
        }

        
    // If the last element is empty, get rid of it
        
    if (empty($uri_array[count($uri_array)-1])) {
            
    array_pop($uri_array);
        }

        return 
    $uri_array;


    Have googled and looked at PHP manual online?

    The regular expression has an ending delimiter, '~'

    So not sure?

    Thanks
    Last edited by ScallioXTX; Oct 15, 2013 at 13:45. Reason: Wrapped code in [php][/php]

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,096
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    That's very weird, it looks like that should work, and it does when I test it here (PHP 5.4)
    Does APP_FOLDER contain a value? If so, what is it?

    Also, that function can be shortened to

    PHP Code:
    function parse_uri()
    {
        
    $uri $_SERVER['REQUEST_URI'];
        if ((
    strpos($uriAPP_FOLDER)) === 0)
        {
            
    $uri substr($uristrlen(APP_FOLDER));
        }
        return 
    explode('/'trim($uri'/'));

    Which is also a lot faster since it doesn't regex, which is kind of overkill here
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •