To get a double quoted string (which I cannot change) correctly parsed I have to do following:
$string = '15 Rose Avenue
Irlam
Manchester';
$string = str_replace('
', "
", $string);
print nl2br($string); // demonstrates that the
's are now linebreak characters
So far, so good. But in my given string there are characters like \xC3\xA4
. There are many characters like this (beginning with \x..) How can I get them correctly parsed as shown above with the linebreak?
You can use
$str = stripcslashes($str);
You can escape a \
in single quotes:
$string = str_replace('\
', "
", $string);
But you're going to have a lot of potential replaces if you need to do \\xC3
, etc.... best use a preg_replace_callback()
with a function(callback) to translate them to bytes