|
użytkowników online: 76
|
OPINIE UŻYTKOWNIKÓW
|
Nie jestem webmasterem, ale i na mnie zrobiła wrażenie szybkość reakcji Darka na mój problem. Jego kompetencja i przede wszystkim zupełnie niemodna w dzisiejszych skomercjalizowanych czasach - zwykła ludzka życzliwość dla innego człowieka. Tacy ludzie to dziś gatunek niemal wymarły...
Leszek
Wojskowy Instytut Medyczny
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
html_entity_decode (PHP 4 >= 4.3.0, PHP 5) html_entity_decode --
Convert all HTML entities to their applicable characters
Descriptionstring html_entity_decode ( string string [, int quote_style [, string charset]] )
html_entity_decode() is the opposite of
htmlentities() in that it converts all HTML entities
to their applicable characters from string.
The optional second quote_style parameter lets
you define what will be done with 'single' and "double" quotes. It takes
on one of three constants with the default being
ENT_COMPAT:
Tabela 1. Available quote_style constants | Constant Name | Description |
|---|
| ENT_COMPAT | Will convert double-quotes and leave single-quotes alone. | | ENT_QUOTES | Will convert both double and single quotes. | | ENT_NOQUOTES | Will leave both double and single quotes unconverted. |
The ISO-8859-1 character set is used as default for the optional third
charset. This defines the character set used in
conversion.
Following character sets are supported in PHP 4.3.0 and later.
Tabela 2. Supported charsets | Charset | Aliases | Description |
|---|
| ISO-8859-1 | ISO8859-1 |
Western European, Latin-1
| | ISO-8859-15 | ISO8859-15 |
Western European, Latin-9. Adds the Euro sign, French and Finnish
letters missing in Latin-1(ISO-8859-1).
| | UTF-8 | |
ASCII compatible multi-byte 8-bit Unicode.
| | cp866 | ibm866, 866 |
DOS-specific Cyrillic charset.
This charset is supported in 4.3.2.
| | cp1251 | Windows-1251, win-1251, 1251 |
Windows-specific Cyrillic charset.
This charset is supported in 4.3.2.
| | cp1252 | Windows-1252, 1252 |
Windows specific charset for Western European.
| | KOI8-R | koi8-ru, koi8r |
Russian. This charset is supported in 4.3.2.
| | BIG5 | 950 |
Traditional Chinese, mainly used in Taiwan.
| | GB2312 | 936 |
Simplified Chinese, national standard character set.
| | BIG5-HKSCS | |
Big5 with Hong Kong extensions, Traditional Chinese.
| | Shift_JIS | SJIS, 932 |
Japanese
| | EUC-JP | EUCJP |
Japanese
|
Notatka:
Any other character sets are not recognized and ISO-8859-1 will be used
instead.
Przykład 1. Decoding HTML entities |
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; echo $b; function unhtmlentities($string)
{
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
}
$c = unhtmlentities($a);
echo $c; ?>
|
|
Notatka:
You might wonder why trim(html_entity_decode(' ')); doesn't
reduce the string to an empty string, that's because the ' '
entity is not ASCII code 32 (which is stripped by
trim()) but ASCII code 160 (0xa0) in the default ISO
8859-1 characterset.
See also htmlentities(),
htmlspecialchars(),
get_html_translation_table(),
and urldecode().
User Contributed Noteshurricane at cyberworldz dot org
23-Dec-2005 05:33
I shortened the function repace_num_entity a bit to make more understandable and clean. Maybe now someone sees the problem it possibly has... (as mentioned below)
<?php
function replace_num_entity($ord) {
$ord = $ord[1];
if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match)) $ord = hexdec($match[1]);
else $ord = intval($ord);
$no_bytes = 0;
$byte = array();
if ($ord < 128) return chr($ord);
if ($ord < 2048) $no_bytes = 2;
else if ($ord < 65536) $no_bytes = 3;
else if ($ord < 1114112) $no_bytes = 4;
else return;
switch($no_bytes) {
case 2: $prefix = array(31, 192); break;
case 3: $prefix = array(15, 224); break;
case 4: $prefix = array(7, 240);
}
for ($i=0; $i < $no_bytes; ++$i)
$byte[$no_bytes-$i-1] = (($ord & (63 * pow(2,6*$i))) / pow(2,6*$i)) & 63 | 128;
$byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
$ret = '';
for ($i=0; $i < $no_bytes; ++$i) $ret .= chr($byte[$i]);
return $ret;
}
?>
loufoque
08-Oct-2005 10:15
If you want to decode NCRs to utf-8 use this function instead of chr().
function utf8_chr($code)
{
if($code<128) return chr($code);
else if($code<2048) return chr(($code>>6)+192).chr(($code&63)+128);
else if($code<65536) return chr(($code>>12)+224).chr((($code>>6)&63)+128).chr(($code&63)+128);
else if($code<2097152) return chr($code>>18+240).chr((($code>>12)&63)+128)
.chr(($code>>6)&63+128).chr($code&63+128));
}
emilianomartinezluque at yahoo dot com
26-Sep-2005 02:22
I've been using the great replace_num_entity function posted below. But there seems to be some problems with the 128 to 160 characters range. Ie, try:
<?php header("Content-type: text/html; charset=utf-8"); ?>
<html><body>
<?php
for($x=128; $x<161; $x++) {
echo('&#' . $x . '; -- ' . preg_replace_callback('/&#([0-9a-fx]+);/mi', 'replace_num_entity', '&#' . $x . ';') . '</br>');
}
?>
</body></html>
I really don
|