How to replace text with any text and symbols in replacement? Because when i use backslash it`s badly replaced.
$text = 'hello replacement world';
$text = preg_replace('#replacement#ui', '28\01\12', $text);
Result
hello 28 world
Solution to do replace before using pattern
$pattern = '28\01\12';
$pattern = str_replace('\\', '\\\\\\\\', $pattern);
This is just expample, in real work need to use more complicated pattern and replacement will consist any text
See the notes here on backslashes: http://php.net/manual/en/language.types.string.php
If you’re just searching for a simple string to replace, you should consider using
str_replace()instead. It’s less expensive cpu-wise. See here: http://php.net/manual/en/function.str-replace.phpUPDATE: More info on escape sequences: http://www.php.net/manual/en/regexp.reference.escape.php