Why preg_replace throws me a “Unknown modifier” error? [duplicate]

You are using forward-slashes as your regex pattern delimeter, so /<title>(.*)</title>/Ui' will not work (</title> has a forward slash).

You should be able to escape the forward slash or use a different delimiter that is not contained within the pattern, for example

'/<title>(.*)<\/title>/Ui' //(esacaping)


'~<title>(.*)</title>~Ui' //different delimiter

Leave a Comment