Question

I've got the following code

function redireectIfNeeded(){
$url = $_SERVER["REQUEST_URI"];
if(preg_match("/\.php/$", $url))
    header("Location: ".preg_replace("/\.php/",$url));
}

Which is giving me the following error.

[24-Jul-2012 19:14:18] PHP Warning:  preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Unknown modifier '$' in ../dbc.php on line 223

I know I need a delimiter somewhere, but nothing I've tried is working. Can anyone let me know what I need to do?

Was it helpful?

Solution

You must set $ before /

if(preg_match("/\.php$/", $url))
    header("Location: ".preg_replace("/\.php/",$url));
}

After delimiter you can use modificator (s, m or i)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top