tags:

views:

30

answers:

1

I have some text where unicode is written as text like this

There areu25ba 2 boys.

it should be like this

There are&#x25ba 2 boys.

Replace 'u' with '&#x' if there is unicode character.

Thanks in advance

+2  A: 

A naive way would be:

preg_replace('/u([0-9a-fA-F]{4})/','&#x$1;',$string);

But I doubt 'udaff' would appreciate it.

Wrikken
`u25ba;` is invalid.
Gumbo
Erm, D'OH! You're right, will fix in a moment.
Wrikken
Wrikken, I've tried to run this code. but its not printing character.echo(preg_replace('/u[0-9a-fA-F]{4}/', "$1", "u25ba works?"));
EarnWhileLearn
Shahid: you missed an update to the regex itself too (which Gumbo pointed out), now fixed in answer.
Wrikken
Thanks Wrikken and Gumbo. It works
EarnWhileLearn