I've notice when the replacement has \
then the function will not work as expected. So I should escape backslash.
What other character should be escaped? I didn't succeed to find any documentation.
I can't use preg_quote()
because it's used for escaping the pattern and not the replacement.
EDIT AGAIN: here is an example with single quote
which show how the backslash cause problem:
$replacement = '<head>content \0020 content</head>';
$subject = "<head>any header </head>";
$html_text = preg_replace ( "%<head>.*?</head>%s", $replacement, $subject, - 1, $count );
die ( $html_text );$subject, - 1, $count );
echo $html_text;
the above example should print : <head>content \0020 content</head>
. but it's print <head>content <head>any header </head>20 content</head>