preg_replace function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deibys
Forum Newbie
Posts: 1
Joined: Fri Nov 28, 2003 2:20 am

preg_replace function

Post by deibys »

Can anyone help me with this?
I have an string and it has strings like this:
{i:xxxx} where xxxx is an hexadecimal number , I need to trasform this into something like this:
&#X; where X is the decimal conversion of xxxx
I am currently using something like this , but it does not work:

$string=preg_replace( "{i:([0-9A-F]{4})}",chr(38).chr(35).hexdec("$1").chr(59),$string);

for an string like this {i:F991}, it returns :
{} and I want to return &#63889

63889 is the hexadecimal conversion of F981

I really appreciate any help :lol:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

$string="{i:F991}";
  $string=preg_replace("/{i:(ї0-9A-F]{4})}/e","chr(38).chr(35).hexdec("\\1").chr(59)",$string);
  echo $string."\n";
Post Reply