suche nach in der

htmlspecialchars> <htmlentities
Last updated: Fri, 18 May 2012

view this page in

htmlspecialchars_decode

(PHP 5 >= 5.1.0)

htmlspecialchars_decode Konvertiert besondere HTML-Auszeichnungen zurück in Buchstaben

Beschreibung

string htmlspecialchars_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 ] )

Diese Funktion ist das Gegenstück zu htmlspecialchars(). Sie konvertiert besondere HTML-Auszeichnungen zurück in Buchstaben.

Die konvertierten Auszeichnungen sind: &amp;, &quot; (wenn ENT_NOQUOTES nicht gesetzt ist), &#039; (wenn ENT_QUOTES gesetzt ist), &lt; und &gt;.

Parameter-Liste

string

Der zu dekodierende String.

flags

Eine Bitmaske von einem oder mehreren der folgenden Flags, die die Behandlung von Anführungszeichen, sowie den zu nutzenden Dokumententyp festlegen. Der Standardwert ist ENT_COMPAT | ENT_HTML401.

Verfügbare flags-Konstanten
Konstantenname Beschreibung
ENT_COMPAT Konvertiert doppelte Anführungszeichen und lässt einfache Anführungszeichen unberührt.
ENT_QUOTES Konvertiert sowohl doppelte als auch einfache Anführungszeichen.
ENT_NOQUOTES Lässt sowohl doppelte als auch einfache Anführungszeichen unberührt.
ENT_HTML401 Behandle Code als HTML 4.01.
ENT_XML1 Behandle Code als XML 1.
ENT_XHTML Behandle Code als XHTML.
ENT_HTML5 Behandle Code als HTML 5.

Rückgabewerte

Gibt den dekodierten String zurück.

Changelog

Version Beschreibung
5.4.0 Die Konstanten ENT_HTML401, ENT_XML1, ENT_XHTML und ENT_HTML5 wurden hinzugefügt.

Beispiele

Beispiel #1 Ein htmlspecialchars_decode()-Beispiel

<?php
$str 
"<p>this -&gt; &quot;</p>\n";

echo 
htmlspecialchars_decode($str);

// Beachten Sie, dass die Anführungszeichen nicht konvertiert werden
echo htmlspecialchars_decode($strENT_NOQUOTES);
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

<p>this -> "</p>
<p>this -> &quot;</p>

Siehe auch



add a note add a note User Contributed Notes
htmlspecialchars_decode
17-Aug-2006 02:49
This should be the best way to do it.
(Reposted because the other one seems a bit slower and because those who used the code under called it htmlspecialchars_decode_php4)

<?php

if ( !function_exists('htmlspecialchars_decode') )
{
    function
htmlspecialchars_decode($text)
    {
        return
strtr($text, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
    }
}

?>
TheSin
09-May-2006 11:51
Here is how you can get this function in php < 5.1, just make sure this function is before you try and call the function.

if (!function_exists('htmlspecialchars_decode')) {
        function htmlspecialchars_decode($str, $options="") {
                $trans = get_html_translation_table(HTML_SPECIALCHARS, $options);

                $decode = ARRAY();
                foreach ($trans AS $char=>$entity) {
                        $decode[$entity] = $char;
                }

                $str = strtr($str, $decode);

                return $str;
        }
}
se at designlinks dot net
14-Dec-2005 05:43
The code supplied by or-k at or-k dot com (14-Sep-2005 09:15) is better served using html_entity_decode() for PHP>=4.3.0.
geoffers@gmail (14-Jul-2005 01:38) offers the best htmlspecialchars_decode() for php4 users.
or-k at or-k dot com
14-Sep-2005 11:15
that works also with &auml; and &quot; and so on.
get_html_translation_table(HTML_ENTITIES) => offers more characters than HTML_SPECIALCHARS

function htmlspecialchars_decode_PHP4($uSTR)
{
 return strtr($uSTR, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES)));
}
geoffers@gmail
14-Jul-2005 03:38
[Update of previous note, having noticed I forgot to put in quote style]

PHP4 Compatible function:

<?php

function htmlspecialchars_decode_php4 ($str, $quote_style = ENT_COMPAT) {
    return
strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
}

?>
geoffers at gmail dot com
14-Jul-2005 03:30
For PHP4 Compatibility:

<?php

function htmlspecialchars_decode_php4 ($str) {
    return
strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}

?>

htmlspecialchars> <htmlentities
Last updated: Fri, 18 May 2012