Forum Moderators: coopster
$patterns[0] = '/\[/';
$patterns[1] = '/\]/';
$replacements[0] = '<';
$replacements[1] = '>';$text2 = preg_replace($patterns, $replacements, $text);
I'm still interested whether
ord and backreferences can play nicely together.
I'm still interested whether ord and backreferences can play nicely together.
That would be surprising, wouldn't it? In other words, the "replace" expression is first evaluated, then sent to the regex engine. You're asking it to do the opposite. So in your case,
ord("\\1") evaluates to ASCII value of the first character of the string "\1" which evaluates to 92. chr(92-31) evaluates to "="
so this expression
$text2 = preg_replace($pattern, chr(ord("\\1")-31), $text);
is the same as
$text2 = preg_replace($pattern, "=", $text);
So it should be changing all your brackets to "=".
s/([^\w\s])/ sprintf('\0%o;', ord($1)) /ge; This translates a whole slew of characters (anything that's not a word or whitespace character) into an octal escape sequence. Is there a way to do this in PHP?
I'm not trying to start a "language death match" here -- just coming up to speed with PHP.