Page 1 of 1

Replacing HEX with HEX using preg_replace()

Posted: Thu Sep 20, 2007 6:49 pm
by geekhunk
Hello,

This might be more of a PHP-thing than REGEX, but here's my problem:

I am using a HEX value to find and replace 'white spaces' with 'x':
take this example: $string = preg_replace('/[\x{20}]/u', 'x', $string);

But I want 'x' to be a HEX number that replaces '20', I have tried the following with no luck:
$string = preg_replace('/[\x{20}]/u', '\x{21}', $string);

I am replacing it with somthing outside of the displayable charecter range, so the replacement has to be in (and stored as) HEX form, can anyone help?

Posted: Thu Sep 20, 2007 9:39 pm
by feyd
I'm having a tough time trying to figure out what you're actually trying to do with the pattern. Do you want to look for the literal string "\x{20}", "20" or a space, as 0x20 is represented in ASCII?