PHP ကျူတိုရီရယ်

PHP ပင်မစာမျက်နှာ PHP မိတ်ဆက် PHP ထည့်သွင်းပါ။ PHP Syntax PHP မှတ်ချက်များ PHP Variables များ PHP Echo / Print PHP Data အမျိုးအစားများ PHP စာတန်းများ PHP နံပါတ်များ PHP သင်္ချာ PHP Constants PHP Operator များ PHP If...Else...Elseif PHP Switch PHP Loops PHP လုပ်ဆောင်ချက်များ PHP Arrays PHP Superglobals PHP RegEx

PHP Forms

PHP Form ကိုင်တွယ်ခြင်း။ PHP Form Validation PHP Form လိုအပ်ပါသည်။ PHP Form URL/E-mail PHP Form ပြီးပါပြီ။

PHP အဆင့်မြင့်

PHP နေ့စွဲနှင့် အချိန် PHP ပါဝင်ပါတယ်။ PHP ဖိုင်ကိုင်တွယ်ခြင်း PHP ဖိုင်ကို ဖွင့်/ဖတ်ပါ။ PHP ဖိုင်ကို ဖန်တီး/ရေးပါ။ PHP ဖိုင်ကို တင်ခြင်း။ PHP Cookies PHP စက်ရှင်များ PHP Filters PHP Filters Advanced PHP ပြန်ခေါ်ခြင်းလုပ်ဆောင်ချက်များ PHP JSON PHP ခြွင်းချက်

PHP OOP

PHP OOP ဆိုတာဘာလဲ PHP အတန်းများ/အရာဝတ္ထုများ PHP Constructor PHP Destructor PHP Access Modifiers PHP Inheritance PHP Constants PHP Abstract အတန်းများ PHP မျက်နှာပြင်များ PHP လက္ခဏာများ PHP Static Methods PHP Static Properties PHP Namespaces PHP Iterables

MySQL ဒေတာဘေ့စ်

MySQL ဒေတာဘေ့စ် MySQL ချိတ်ဆက်မှု MySQL သည် DB ကိုဖန်တီးပါ။ MySQL ဇယားဖန်တီးပါ။ MySQL သည် Data ကိုထည့်သွင်းပါ။ MySQL နောက်ဆုံး ID ကိုရယူပါ။ MySQL တွင် Multiple ထည့်သွင်းပါ။ MySQL ပြင်ဆင်ထားသည်။ MySQL Data ကို ရွေးပါ။ MySQL ဘယ်မှာလဲ။ MySQL Order By MySQL က Data တွေကို ဖျက်လိုက်ပါ။ MySQL အပ်ဒိတ်ဒေတာ MySQL ကန့်သတ်ဒေတာ

PHP XML

PHP XML ပါဆာများ PHP SimpleXML Parser PHP SimpleXML - ရယူပါ။ PHP XML Expat PHP XML DOM

PHP - AJAX

AJAX နိဒါန်း AJAX PHP AJAX ဒေတာဘေ့စ် AJAX XML AJAX တိုက်ရိုက်ရှာဖွေမှု AJAX စစ်တမ်း

PHP ဥပမာများ

PHP ဥပမာများ PHP Compiler PHP Quiz PHP လေ့ကျင့်ခန်းများ PHP Certificate

PHP အ ကိုးအကား

PHP ခြုံငုံသုံးသပ်ချက် PHP Array PHP ပြက္ခဒိန် PHP နေ့စွဲ PHP လမ်းညွှန် PHP အမှား PHP ခြွင်းချက် PHP ဖိုင်စနစ် PHP Filter PHP FTP PHP JSON PHP သော့ချက်စာလုံးများ PHP Libxml PHP Mail PHP သင်္ချာ PHP ထွေ PHP MySQLi PHP ကွန်ရက် PHP Output Control PHP RegEx PHP SimpleXML PHP Stream PHP String PHP Variable ကိုင်တွယ်ခြင်း။ PHP XML Parser PHP Zip PHP အချိန်ဇုန်များ

PHP htmlspecialchars() လုပ်ဆောင်ချက်

❮ PHP String အကိုးအကား

ဥပမာ

ကြိုတင်သတ်မှတ်ထားသော စာလုံး "<" (ထက်နည်းသော) နှင့် ">" (ထက်ကြီးသည်) ကို HTML entities သို့ ပြောင်းပါ-

<?php
$str = "This is some <b>bold</b> text.";
echo htmlspecialchars($str);
?>

အထက်ဖော်ပြပါ code ၏ HTML အထွက်သည် (View Source) ဖြစ်လိမ့်မည်။

<!DOCTYPE html>
<html>
<body>
This is some &lt;b&gt;bold&lt;/b&gt; text.
</body>
</html>

အထက်ဖော်ပြပါ ကုဒ်၏ ဘရောက်ဆာ၏ ထွက်ပေါက်မှာ-

This is some <b>bold</b> text.

အဓိပ္ပါယ်နှင့် အသုံးပြုမှု

htmlspecialchars() လုပ်ဆောင်ချက်သည် အချို့သော ကြိုတင်သတ်မှတ်ထားသော စာလုံးများကို HTML entities အဖြစ်သို့ ပြောင်းပေးသည်။

ကြိုတင်သတ်မှတ်ထားသော ဇာတ်ကောင်များမှာ-

  • & (ampersand) ဖြစ်လာသည် &
  • "(ကိုးကားနှစ်ချက်) သည် "
  • ' (ကိုးကားချက်) သည် '
  • < (အောက်) ဖြစ်သွားသည် <
  • > (ထက်ကြီးသည်) >

အကြံပြုချက်- အထူး HTML အရာများကို ဇာတ်ကောင်များထံ ပြန်ပြောင်းရန်၊ htmlspecialchars_decode() လုပ်ဆောင်ချက်ကို အသုံးပြုပါ။


အထားအသို

htmlspecialchars(string,flags,character-set,double_encode)

ကန့်သတ်တန်ဖိုးများ

Parameter Description
string Required. Specifies the string to convert
flags Optional. Specifies how to handle quotes, invalid encoding and the used document type.

The available quote styles are:

  • ENT_COMPAT - Default. Encodes only double quotes
  • ENT_QUOTES - Encodes double and single quotes
  • ENT_NOQUOTES - Does not encode any quotes

Invalid encoding:

  • ENT_IGNORE - Ignores invalid encoding instead of having the function return an empty string. Should be avoided, as it may have security implications.
  • ENT_SUBSTITUTE - Replaces invalid encoding for a specified character set with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD; instead of returning an empty string.
  • ENT_DISALLOWED - Replaces code points that are invalid in the specified doctype with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD;

Additional flags for specifying the used doctype:

  • ENT_HTML401 - Default. Handle code as HTML 4.01
  • ENT_HTML5 - Handle code as HTML 5
  • ENT_XML1 - Handle code as XML 1
  • ENT_XHTML - Handle code as XHTML
character-set Optional. A string that specifies which character-set to use.

Allowed values are:

  • UTF-8 - Default. ASCII compatible multi-byte 8-bit Unicode
  • ISO-8859-1 - Western European
  • ISO-8859-15 - Western European (adds the Euro sign + French and Finnish letters missing in ISO-8859-1)
  • cp866 - DOS-specific Cyrillic charset
  • cp1251 - Windows-specific Cyrillic charset
  • cp1252 - Windows specific charset for Western European
  • KOI8-R - Russian
  • BIG5 - Traditional Chinese, mainly used in Taiwan
  • GB2312 - Simplified Chinese, national standard character set
  • BIG5-HKSCS - Big5 with Hong Kong extensions
  • Shift_JIS - Japanese
  • EUC-JP - Japanese
  • MacRoman - Character-set that was used by Mac OS

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.

double_encode Optional. A boolean value that specifies whether to encode existing html entities or not.
  • TRUE - Default. Will convert everything
  • FALSE - Will not encode existing html entities


နည်းပညာဆိုင်ရာအသေးစိတ်

ပြန်ပို့တန်ဖိုး- ပြောင်းထားသောစာကြောင်း ကို

ပြန်ပေး သည်
PHP ဗားရှင်း- 4+
ပြောင်းလဲမှုမှတ်တမ်း- PHP 5.6 - အက္ခရာ-အစုံ ပါရာမီတာ အတွက် မူရင်းတန်ဖိုးကို ပုံသေ စာလုံး ရေ (ဖွဲ့စည်းမှုတွင်) တန်ဖိုးသို့ ပြောင်းလဲခဲ့သည်။
PHP 5.4 - ဇာတ်ကောင်သတ်မှတ်ထားသော ကန့ ်သတ်ဘောင်တန်ဖိုးကို UTF-8 သို့ ပြောင်းလဲခဲ့သည်။
PHP 5.4 - Added ENT_SUBSTITUTE၊ ENT_DISALLOWED၊ ENT_HTML401၊ ENT_HTML5၊ ENT_XML1 နှင့် ENT_XHTML
PHP 5.3 - ထည့်ထားသော ENT_IGNORE ကိန်းသေ။
PHP 5.2.3 - double_encode ကန့်သတ်ဘောင်ကို ထည့်ထားသည်။
PHP 4.1 - ဇာတ်ကောင်သတ်မှတ်ထားသော ကန့်သတ် ဘောင်ကို ထည့် ထားသည်။

နောက်ထပ် ဥပမာများ

ဥပမာ

အချို့သော ကြိုတင်သတ်မှတ်ထားသော စာလုံးများကို HTML အကြောင်းအရာများသို့ ပြောင်းပါ-

<?php
$str = "Jane & 'Tarzan'";
echo htmlspecialchars($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo htmlspecialchars($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo htmlspecialchars($str, ENT_NOQUOTES); // Does not convert any quotes
?>

အထက်ဖော်ပြပါ code ၏ HTML အထွက်သည် (View Source) ဖြစ်လိမ့်မည်။

<!DOCTYPE html>
<html>
<body>
Jane &amp; 'Tarzan'<br>
Jane &amp; &#039;Tarzan&#039;<br>
Jane &amp; 'Tarzan'
</body>
</html>

အထက်ဖော်ပြပါ ကုဒ်၏ ဘရောက်ဆာ၏ ထွက်ပေါက်မှာ-

Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'

ဥပမာ

ကိုးကားနှစ်ဆကို HTML အကြောင်းအရာသို့ ပြောင်းပါ-

<?php
$str = 'I love "PHP".';
echo htmlspecialchars($str, ENT_QUOTES); // Converts double and single quotes
?>

အထက်ဖော်ပြပါ code ၏ HTML အထွက်သည် (View Source) ဖြစ်လိမ့်မည်။

<!DOCTYPE html>
<html>
<body>
I love &quot;PHP&quot;.
</body>
</html>

အထက်ဖော်ပြပါ ကုဒ်၏ ဘရောက်ဆာ၏ ထွက်ပေါက်မှာ-

I love "PHP".

❮ PHP String အကိုးအကား