PHP special Character conversion entity function summary

Source: Internet
Author: User
Data-id= "1190000005008217" data-license= "sa" >

1. htmlspecialchars($string, $flag) (convert special characters to HTML entities converting special characters to HTML entities)

预定义的字符是:& (和号)成为 &" (双引号)成为 "' (单引号)成为 '< (小于)成为 <> (大于)成为 >

$flag defaults toENT_COMPAT | ENT_HTML401

constant Name Description
Ent_compat Convert double quotes without converting single quotes.
Ent_quotes Both single and double quotation marks are converted.
Ent_noquotes Both single and double quotation marks are not converted.
ent_html401 Processed as HTML 4.01 encoding.
Ent_xml1 Processed as XML 1 encoding.
Ent_xhtml Processed as XHTML encoding.
Ent_html5 Processed as HTML 5 encoding.

Exp:

    $str = '"2015竞赛&"';    echo htmlspecialchars($str); //"2015竞赛&"quot;

2. htmlspecialchars_decode($string, $flag) (in contrast to the above, convert special HTML entities back to normal characters)

Exp

    $str  =  "

this -> "

\n" ; echo htmlspecial_decode($str); // this -> " /*不转换双引号*/ echo htmlspecial_decode($str, ENT_NOQUOTES); // this -> "

3. Htmlentities

`htmlentities($string, $flag)`这个函数与htmlspecialchars的区别网上教程说是也会转换中文,但是我本地php5.5测试两个效果一样
   $str='测试页面';    echo htmlentities($str);      $str='测试页面';    echo htmlspecialchars($str);

4. Html_entity_decode

是`htmlentities`的反函数  

5.nl2br

转换换行符(\n(unix), \r(Mac), \r\n(Win))为`
`

The above describes the PHP special character conversion entity function summary, including special characters, PHP content, I hope the PHP tutorial interested in a friend helpful.

  • 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.