Connecting Tech Pros Worldwide Help | Site Map

Replacing HEX with HEX in PHP - preg_replace()

Banned
 
Join Date: May 2006
Posts: 4
#1: Sep 21 '07
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:
Expand|Select|Wrap|Line Numbers
  1. $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:
Expand|Select|Wrap|Line Numbers
  1. $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?
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Sep 21 '07

re: Replacing HEX with HEX in PHP - preg_replace()


Heya, nobugus.

I award 5 points for creative use of B tags. However, I must deduct 5 points for failing to use CODE tags.

Better luck next time.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#3: Sep 21 '07

re: Replacing HEX with HEX in PHP - preg_replace()


You should be able to do this with a simple str_replace():
Expand|Select|Wrap|Line Numbers
  1. $string = str_replace("\x20", "\x21", $string);
  2.  
Reply