Λειτουργία html_entity_decode() του PHP
Παράδειγμα
Μετατρέπει τις προκαθορισμένες HTML entity "<" (μικρότερο από) και ">" (μεγαλύτερο από) σε χαρακτήρες:
<?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() μετατρέπει τις προκαθορισμένες HTML entity σε χαρακτήρες.
Οι HTML entity που θα αποκωδικοποιηθούν είναι:
- & Αποκωδικοποιείται σε & (και)
- " Αποκωδικοποιείται σε " (διπλό παράγον)
- ' Αποκωδικοποιείται σε ' (μονοπαράγοντας)
- < Αποκωδικοποιείται σε < (μικρότερο από)
- > Αποκωδικοποιείται σε > (μεγαλύτερο από)
htmlspecialchars_decode() είναι η αντίθετη λειτουργία της 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".