Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

htmlspecialchars_decode

(PHP 5 >= 5.1.0RC1)

htmlspecialchars_decode --  Преобразует специальные HTML-сущности обратно в соответствующие символы

Описание

string htmlspecialchars_decode ( string string [, int quote_style] )

Эта функция является обратной к htmlspecialchars(). Она преобразует специальные HTML-сущности обратно в соответствующие символы.

Конвертируемые сущности : &, " (когда ENT_NOQUOTES не установлена), ' (когда ENT_QUOTES установлена), < and >.

Список параметров

string

Строка, которую надо преобразовать

quote_style

Стиль ковычек. Может принимать значение одной из следующих констант:

Таблица 1. Константы quote_style

Имя константыОписание
ENT_COMPATПреобразовывать двойные ковычки и пропускать одинарные (по умолчанию)
ENT_QUOTESПреобразовывать и двойные, и одинарные ковычки
ENT_NOQUOTESНе преобразовывать ни двойные, ни одинарные ковычки

Возвращаемые значения

Возвращает преобразованную строку.

Примеры

Пример 1. Пример использования функции htmlspecialchars_decode()

<?php
$str
= '<p>this -&gt; &quot;</p>';

echo
htmlspecialchars_decode($str);

// обратите внимание, что в данном случае ковычки не будут преобразованы
echo htmlspecialchars_decode($str, ENT_NOQUOTES);
?>

Результат выполнения данного примера:

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



htmlspecialchars> <htmlentities
Last updated: Sat, 27 Jan 2007
 
add a note add a note User Contributed Notes
htmlspecialchars_decode
Wout
28-Jul-2007 09:06
The following replacement for PHP 4 is a little more complete, as the quote_style is taken into account as well:

if (!function_exists("htmlspecialchars_decode")) {
    function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
        return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
    }
}
17-Aug-2006 05: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 02: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 08: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 02: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 06: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 06: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: Sat, 27 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571