دالة PHP html_entity_decode ()
مثال
تحويل كيانات HTML إلى أحرف:
<?php
$str = '<a href="https://www.w3schools.com">w3schools.com</a>';
echo html_entity_decode($str);
?>
سيكون ناتج HTML للشفرة أعلاه (عرض المصدر):
<a href="https://www.w3schools.com">w3schools.com</a>
سيكون إخراج المتصفح للشفرة أعلاه:
التعريف والاستخدام
تقوم الدالة html_entity_decode () بتحويل كيانات HTML إلى أحرف.
الدالة html_entity_decode () هي عكس htmlentities () .
بناء الجملة
html_entity_decode(string,flags,character-set)
قيمه المعامل
Parameter | Description |
---|---|
string | Required. Specifies the string to decode |
flags | Optional. Specifies how to handle quotes and which document type to use. The available quote styles are:
Additional flags for specifying the used doctype:
|
character-set | Optional. A string that specifies which character-set to use. Allowed values are:
Note: Unrecognized character-sets will be ignored and replaced by ISO-8859-1 in versions prior to PHP 5.4. As of PHP 5.4, it will be ignored an replaced by UTF-8. |
تفاصيل تقنية
قيمة الإرجاع: | ترجع السلسلة المحولة |
---|---|
إصدار PHP: | 4.3.0+ |
التغيير: | PHP 5.6 - تم تغيير القيمة الافتراضية لمعلمة مجموعة الأحرف
إلى قيمة مجموعة الأحرف الافتراضية (في التكوين). PHP 5.4 - تم تغيير القيمة الافتراضية لمعلمة مجموعة الأحرف إلى UTF-8. PHP 5.4 - تمت إضافة ENT_HTML401 و ENT_HTML5 و ENT_XML1 و ENT_XHTML. PHP 5.0 - دعم إضافي للترميزات متعددة البايت |
مزيد من الأمثلة
مثال
قم بتحويل بعض كيانات HTML إلى أحرف:
<?php
$str = "Albert Einstein said: 'E=MC²'";
echo
html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo html_entity_decode($str, ENT_QUOTES); // Converts double
and single quotes
echo "<br>";
echo html_entity_decode($str, ENT_NOQUOTES); // Does not
convert any quotes
?>
سيكون ناتج HTML للشفرة أعلاه (عرض المصدر):
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'
سيكون إخراج المتصفح للشفرة أعلاه:
Albert Einstein said: 'E=MC²'
Albert Einstein said: 'E=MC²'
Albert
Einstein said: 'E=MC²'
مثال
قم بتحويل بعض كيانات HTML إلى أحرف ، باستخدام مجموعة الأحرف الأوروبية الغربية:
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "UTF-8");
?>
سيكون ناتج HTML للشفرة أعلاه (عرض المصدر):
My name is Øyvind Åsane. I'm Norwegian.
سيكون إخراج المتصفح للشفرة أعلاه:
My name is Øyvind Åsane. I'm Norwegian.
❮ مرجع سلسلة PHP