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


/*
*
*
*/
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

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


function parse_uri()
{
    $uri = $_SERVER['REQUEST_URI'];
    if ((strpos($uri, APP_FOLDER)) === 0)
    {
        $uri = substr($uri, strlen(APP_FOLDER));
    }
    return explode('/', trim($uri, '/'));
}

Which is also a lot faster since it doesn’t regex, which is kind of overkill here :slight_smile: