PHP html_entity_decode() function
مثال
تحويل الشيفرة المحددة مسبقًا "<" (أصغر من) و ">" (أكبر من) إلى أحرف:
<?php $str = "هذا نص قوي <b>قوي</b>."; echo htmlspecialchars_decode($str); ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> هذا نص قوي <b>قوي</b>. </body> </html>
Browser output of the above code:
هذا نص قوي.
التعريف والاستخدام
htmlspecialchars_decode() يقوم بتحويل الشيفرة المحددة مسبقًا إلى أحرف.
الشيفرة الحالية التي سيتم فك شيفرتها هي:
- & يتم تحويله إلى & (وال)
- " يتم تحويله إلى " (أقواس مزدوجة)
- ' يتم تحويله إلى ' (أقواس مائلة)
- < يتم تحويله إلى < (أصغر من)
- > يتم تحويله إلى > (أكبر من)
htmlspecialchars_decode() هي العكس من function htmlspecialchars().
النحو
htmlspecialchars_decode(string,flags)
الإعدادات | الوصف |
---|---|
string | مطلوب. تحديد النص الذي سيتم فك شيفرته. |
flags |
اختياري. تحديد كيفية معالجة الإشارات واستخدام نوع ملف. أنواع الإشارات المتاحة:
تحديد الأعلام الإضافية للنوع الملف المستخدم:
|
Technical Details
Return Value: | Return the converted string. |
PHP Version: | 5.1.0+ |
Update Log: |
In PHP 5.4, additional flags were added to specify the document type to be used:
|
More Examples
Example 1
Convert predefined HTML entities to characters:
<?php $str = "Bill & 'Steve'"; echo htmlspecialchars_decode($str, ENT_COMPAT); // Convert only double quotes echo "<br>"; echo htmlspecialchars_decode($str, ENT_QUOTES); // Convert double quotes and single quotes echo "<br>"; echo htmlspecialchars_decode($str, ENT_NOQUOTES); // Do not convert any quotes ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> Bill & 'Steve'<br> Bill & 'Steve'<br> Bill & 'Steve' </body> </html>
Browser output of the above code:
Bill & 'Steve' Bill & 'Steve' Bill & 'Steve'
Example 2
Convert predefined HTML entities to double quotes:
<?php $str = 'I love "PHP".'; echo htmlspecialchars_decode($str, ENT_QUOTES); // Convert double quotes and single quotes ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> I love "PHP". </body> </html>
Browser output of the above code:
I love "PHP".