By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Convert text

P: n/a
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!

Jun 28 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


This is the same question that McHenry asked today.
The answer is simple: use html_entity_decode():
<?php
echo html_entity_decode('Thuyền Và Biển');
?>

HTH.
Ruben.
Jun 28 '06 #2

P: n/a
It work when out in brower! But when I save to file, nothing change! :)
Ruben van Engelenburg wrote:
This is the same question that McHenry asked today.
The answer is simple: use html_entity_decode():
<?php
echo html_entity_decode('Thuyền Và Biển');
?>

HTH.
Ruben.


Jun 28 '06 #3

P: n/a

ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


What text char-set/encoding do you want the text to be?

Jun 28 '06 #4

P: n/a
I want to convert it to UTF-8 encoding
Chung Leong wrote:
ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


What text char-set/encoding do you want the text to be?


Jun 29 '06 #5

P: n/a

ngocviet wrote:
I want to convert it to UTF-8 encoding
Chung Leong wrote:
ngocviet wrote:
I have a text like this: "Thuyền Và Biển"
How to convert it to: "Thuyền V* Biển"
Please help!


What text char-set/encoding do you want the text to be?


You will have to do it manually using preg_replace_callback(), as I
don't believe html_entity_decode() is capable of decoding such
entities. Here're the basics:

$text = preg_replace_callback('/&#(d+);/',
'numeric_html_entity_replace', $text);

function numeric_html_entity_replace($m) {
$unicode = (int) $m[1];
$utf8 = /* encode the Uncode value */
return $utf8
}

The tricky part is converting the Unicode value to a UTF-8 string.

Jun 29 '06 #6

P: n/a
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:11**********************@y41g2000cwy.googlegr oups.com...

You will have to do it manually using preg_replace_callback(), as I
don't believe html_entity_decode() is capable of decoding such
entities. Here're the basics:

$text = preg_replace_callback('/&#(d+);/',
'numeric_html_entity_replace', $text);

function numeric_html_entity_replace($m) {
$unicode = (int) $m[1];
$utf8 = /* encode the Uncode value */
return $utf8
}

The tricky part is converting the Unicode value to a UTF-8 string.


There's a solution for that at php.net

http://fi.php.net/manual/en/function.chr.php#55978

chr seems to be ASCII-only (which is kinda stupid if you think about it,
plenty of utf implementations these days) but "grey" had written a
workaround for it.
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)

Jun 30 '06 #7

P: n/a
Thanks Kimmo Laine!
It solves my problem!
Code:

function unichr($dec)
{
if ($dec < 128) {
$utf = chr($dec);
} else if ($dec < 2048) {
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
} else {
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
return $utf;
}

$str = "Thuyền Và Biển";
$str = preg_replace("/&#(\d{2,5});/e", "unichr($1);", $str);
echo $str;

Kimmo Laine wrote:
There's a solution for that at php.net

http://fi.php.net/manual/en/function.chr.php#55978

chr seems to be ASCII-only (which is kinda stupid if you think about it,
plenty of utf implementations these days) but "grey" had written a
workaround for it.
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jul 2 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.