PHP htmlspecialchars () function example tutorial

Source: Internet
Author: User

PHP htmlspecialchars () function example tutorial

Definition and usage
The htmlspecialchars () function converts some predefined characters into HTML entities.

The predefined characters are:

& (Symbol) become &
"(Double quotation marks)"
'(Single quotes)'
"(Less than)"
"(Greater than)"
Syntax

Htmlspecialchars (string, quotestyle, character-set)
  
Parameter Description
String Required. Specifies the string to convert
Quotestyle
  • Optional. Specifies how to encode a single, double quotation marks. The current quote method is ENT_COMPAT-default. Encode only double quotes ENT_QUOTES-encode double and single quotes E NT_NOQUOTES-do not encode any quotation
Character-set
Optional. Character set specified by the string. The value is equivalent to ISO-8859-1-default. Western European International Organization for Standardization-8859-15-Western Europe (added the euro sign + letters from France and Finland lost in I SO-8 859-1) -8-a s cii compatible with multi-byte 8-bit U n icodecp 866-D OS specific Spanish character set cp 1 251-Windows specific Spanish character set cp1252-specific character set W indows Western Europe K OI8-R-Russian Personal Information Protection Policy-traditional China, mainly used in Taiwan G B2 312-simplified China, the national standard character set personal information protection policy, hong Kong Supplementary Character Set-basket and Hong Kong extension S hi ft _ JIS-Japanese eu c-JA-Japanese
  

Tips and instructions
Note: unrecognized character sets are ignored and replaced by ISO-8859-1.




Example 1

 

<Html> <body> <? Php $ str = "Jane & 'tarzanc'"; echo htmlspecialchars ($ str, ENT_COMPAT); echo "<br/>"; echo htmlspecialchars ($ str, ENT_QUOTES ); echo "<br/>"; echo htmlspecialchars ($ str, ENT_NOQUOTES);?> </Body> 
 
Result.
 
Jane & 'tarzance' Jane & 'tarzanc'
 
      

If you select "View Source File" in the browser window, you will see the following HTML:

 

<Html> <body> Jane & amp; 'tarzanc' <br/> Jane & amp; & #039; Tarzan & #039; <br/> Jane & amp; 'tarzany' </body> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.