Replacing HEX with HEX using preg_replace()

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
geekhunk
Forum Newbie
Posts: 1
Joined: Thu Sep 20, 2007 6:43 pm

Replacing HEX with HEX using preg_replace()

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
Post Reply