note 82678 modified in function.htmlentities by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:51:12 +0000 |
| Subject: | note 82678 modified in function.htmlentities by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154897@lists.php.net to get a copy of this message | ||
Hi,
below a method to convert UTF-8 Latin-1 characters to HTML-Entity,
I'm created this to translate string with HTML element on it and i just wont to convert
entities.
<?php
function convertLatin1ToHtml($str) {
$html_entities = array (
"&" => "&", #ampersand
"á" => "á", #latin small letter a
"Ã" => "Â", #latin capital letter A
"â" => "â", #latin small letter a
"Ã" => "Æ", #latin capital letter AE
"æ" => "æ", #latin small letter ae
"Ã" => "À", #latin capital letter A
"Ã " => "à", #latin small letter a
"Ã
" => "Å", #latin capital letter A
"Ã¥" => "å", #latin small letter a
"Ã" => "Ã", #latin capital letter A
"ã" => "ã", #latin small letter a
"Ã" => "Ä", #latin capital letter A
"ä" => "ä", #latin small letter a
"Ã" => "Ç", #latin capital letter C
"ç" => "ç", #latin small letter c
"Ã" => "É", #latin capital letter E
"é" => "é", #latin small letter e
"Ã" => "Ê", #latin capital letter E
"ê" => "ê", #latin small letter e
"Ã" => "È", #latin capital letter E
/*... sorry cutting because limitation of php.net ...
... but the principle is it ;) ... */
"û" => "û", #latin small letter u
"Ã" => "Ù", #latin capital letter U
"ù" => "ù", #latin small letter u
"Ã" => "Ü", #latin capital letter U
"ü" => "ü", #latin small letter u
"Ã" => "Ý", #latin capital letter Y
"ý" => "ý", #latin small letter y
"ÿ" => "ÿ", #latin small letter y
"Ÿ" => "Ÿ", #latin capital letter Y
);
foreach ($html_entities as $key => $value) {
$str = str_replace($key, $value, $str);
}
return $str;
}
?>
--was--
Hi,
below a method to convert UTF-8 Latin-1 characters to HTML-Entity,
I'm created this to translate string with HTML element on it and i just wont to convert
entities.
function convertLatin1ToHtml($str) {
$html_entities = array (
"&" => "&", #ampersand
"á" => "á", #latin small letter a
"Ã" => "Â", #latin capital letter A
"â" => "â", #latin small letter a
"Ã" => "Æ", #latin capital letter AE
"æ" => "æ", #latin small letter ae
"Ã" => "À", #latin capital letter A
"Ã " => "à", #latin small letter a
"Ã
" => "Å", #latin capital letter A
"Ã¥" => "å", #latin small letter a
"Ã" => "Ã", #latin capital letter A
"ã" => "ã", #latin small letter a
"Ã" => "Ä", #latin capital letter A
"ä" => "ä", #latin small letter a
"Ã" => "Ç", #latin capital letter C
"ç" => "ç", #latin small letter c
"Ã" => "É", #latin capital letter E
"é" => "é", #latin small letter e
"Ã" => "Ê", #latin capital letter E
"ê" => "ê", #latin small letter e
"Ã" => "È", #latin capital letter E
... sorry cutting because limitation of php.net ...
... but the principle is it ;) ...
"û" => "û", #latin small letter u
"Ã" => "Ù", #latin capital letter U
"ù" => "ù", #latin small letter u
"Ã" => "Ü", #latin capital letter U
"ü" => "ü", #latin small letter u
"Ã" => "Ý", #latin capital letter Y
"ý" => "ý", #latin small letter y
"ÿ" => "ÿ", #latin small letter y
"Ÿ" => "Ÿ", #latin capital letter Y
);
foreach ($html_entities as $key => $value) {
$str = str_replace($key, $value, $str);
}
return $str;
}
http://php.net/manual/en/function.htmlentities.php