regex replace hex with &#ddd;

J

John

Hi

$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;

I'm trying to replace any character C0 to FF with

I cannot get the ord to evaluate. I have appended the 'e'

Any idea what I'm doing wrong?

Regards
John
 
S

sln

Hi

$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;

I'm trying to replace any character C0 to FF with

I cannot get the ord to evaluate. I have appended the 'e'

Any idea what I'm doing wrong?

Regards
John
When its evaled it needs to be quoted.
Don't forget to escape the hex notation.

$x = "\xc0 \xff";
$x =~s |([\xc0-\xff])|'&#'.ord($1).';'|eg;
print $x;

-sln
 
J

John

Hi

$x =~s |([xc0-xff])|\&\#ord($1)\;|eg;

I'm trying to replace any character C0 to FF with

I cannot get the ord to evaluate. I have appended the 'e'

Any idea what I'm doing wrong?

Regards
John
When its evaled it needs to be quoted.
Don't forget to escape the hex notation.

$x = "\xc0 \xff";
$x =~s |([\xc0-\xff])|'&#'.ord($1).';'|eg;
print $x;

-sln

Many thanks. I completely messed up the second half. But I see the
solution now.

Regards
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top