Page 1 of 1

preg_replace function

Posted: Fri Nov 28, 2003 2:20 am
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:

Posted: Fri Nov 28, 2003 5:38 am
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";