PHP html_entity_decode() လုပ်ဆောင်ချက်
ဥပမာ
HTML အကြောင်းအရာများကို အက္ခရာအဖြစ် ပြောင်းပါ-
<?php
$str = '<a href="https://www.w3schools.com">w3schools.com</a>';
echo html_entity_decode($str);
?>
အထက်ဖော်ပြပါ code ၏ HTML အထွက်သည် (View Source) ဖြစ်လိမ့်မည်။
<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 - Multi-byte ကုဒ်နံပါတ်များအတွက် ပံ့ပိုးမှု ထပ်လောင်းထည့်ထားသည်။ |
နောက်ထပ် ဥပမာများ
ဥပမာ
အချို့သော 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
?>
အထက်ဖော်ပြပါ code ၏ HTML အထွက်သည် (View Source) ဖြစ်လိမ့်မည်။
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");
?>
အထက်ဖော်ပြပါ code ၏ HTML အထွက်သည် (View Source) ဖြစ်လိမ့်မည်။
My name is Øyvind Åsane. I'm Norwegian.
အထက်ဖော်ပြပါ ကုဒ်၏ ဘရောက်ဆာ၏ ထွက်ပေါက်မှာ-
My name is Øyvind Åsane. I'm Norwegian.
❮ PHP String အကိုးအကား