I want to replace every “../” and “script/uploaded” in my string variable to “” !
I have one function like this :
public function mypregReplace($v)
{
return preg_replace(
array("%script/uploaded%" , ""),
array( "[\.\./]" , ""),
$v);
}
but it showa me this error
preg_replace() [function.preg-replace]: Delimiter must not be
alphanumeric or backslash in
what`s wrong on my pattern?!
You have your array wrong. The first array should consist only of patterns, and the second should be the replacement values. You want:
Which can be further simplified to:
You should be using str_replace for this, however. You don’t need regular expressions to match exact strings: