What are the php string conversion functions?
php string conversion functions include: 1. addcslashes function, which uses backslashes to escape characters belonging to a given list in a given string; 2. addslashes function, which uses backslashes to quote strings; 3 , bin2hex function, convert the binary string of the string into a hexadecimal string, etc.
Recommended: "PHP Video Tutorial"
PHP string conversion functions are:
addcslashes: Use backslashes to escape characters in the given string that belong to the given list in C language style. This function accepts two parameters, the first is the string to be escaped, and the second is a list of characters that need to be escaped, and the escaped string is returned, that is, characters belonging to the escaped character list are preceded by a backslash. If the escape character list contains characters such as \n and \r, they will be converted in C language style, while other non-alphanumeric characters with ASCII codes lower than 32 and higher than 126 will be converted to octal representation. When defining an escape list, you can express the range by adding two dots between two characters. The characters in the range will be escaped. When using this method, you need to clear whether you want to escape all the characters in the defined range. characters. If the ASCII code of the end character of the set range is lower than the start character, a warning will be generated and the range will not be created. Instead, the start character, the end character, and all characters in them will be escaped one by one.
addslashes: Use backslashes to quote strings, receive a parameter, the string to be escaped, and return the escaped string. The purpose of escaping is for database query statements You need to add a backslash before certain characters. These characters include single quotes, double quotes, backslashes and NUL characters.
bin2hex: Convert the binary string of the string into a hexadecimal string. The conversion uses byte mode, with the high nibble taking precedence. Equivalent to doing dechex(ord()) on a single character.
chr: Returns the specified character, receives a parameter, and returns a single character specified by the ascii code corresponding to this parameter. It is complementary to ord(). If the value passed in is greater than 256, a single character specified by the ASCII code corresponding to the number modulo 256 will be returned.
convert_cyr_string: Convert Cyrillic characters from one character set to another. It accepts three parameters, the string to be converted, and the original character set type. , the new character set type, returns the converted string. The character set type is a single character, k (koi8-r), w (windows-1251), i (iso8859-5), a (x-cp866), d (x-cp866), m (x-mac-cyrillic) .
convert_uudecode: Decode a uuencode-encoded string, accept a uuencode-encoded string, and return the decoded string. If the decoding fails, return false.
convert_uuencode: Use the uuencode algorithm to encode a string, accept a string to be encoded, and return the encoded string. If the encoding fails, return false.
hex2bin: Converts a hexadecimal string to a binary string, accepts a hexadecimal string, and returns the converted binary representation of the given string. . This method does not convert a hexadecimal number to a binary number. Reciprocal with bin2hex.
html_entity_decode: Convert HTML entities to appropriate characters. Accepts three parameters, the first is the required string to be converted, the second is the optional flag bit, specifies how to handle quotation marks and which document type to use, the default value is ENT_COMPAT|ENT_HTML401, the third parameter Optionally specifies the encoding to use when converting characters. If omitted, starting from PHP 5.6, the value of the php.ini configuration item default-charset is the default value. PHP 5.4 and 5.5 default to UTF-8, and the previous default is ISO-8859-1. Returns the converted character.
htmlentities: Convert characters to HTML escape characters. Accepts four parameters. The first parameter is the required string to be converted. The second and third parameters are the same as the html_entity_decode function. The fourth parameter is an optional Boolean type value. If it is false, it will not be converted. Existing HTML entities, otherwise all are converted, the default is true, and the converted characters are returned. If the string to be converted contains an invalid unit sequence in the specified encoding, and the ENT_IGNORE or ENT_SUBSTITUTE tag is not set, an empty string will be returned. .
htmlspecialchars_decode:将特殊的HTML实体转为普通字符,接受两个参数,第一个为必需的要转换的字符串,第二个为可选的标记位,指定了如何处理引号和使用哪种文档类型,默认值为ENT_COMPAT|ENT_HTML401。返回转换后的字符串。被转换的实体有&, " (没有设置ENT_NOQUOTES 时), ' (设置了 ENT_QUOTES 时), < 以及>。
htmlspecialchars:将特殊字符转换为HTML实体,接受四个参数,与htmlentities函数相同。
ord:返回字符串的ascii码值,接受一个要转换的字符串,返回字符串的ascii值。
quoted_printable_decode:将quoted-printable字符串转换成8bit字符串。
quoted_printable_encode:将8bit字符串转换成quoted-printable字符串。
str_rot13:对字符串执行ROT13转换,忽略非字母表中的字符。如果传入的是编码后的字符,则返回的会是原始字符。
stripcslashes:反引用一个使用addcslashes()转义的字符串。
quotemeta:转义元字符集,将. \ + * ? [ ^ ] ( $ )字符前加反斜杠。如果输入的字符串为空则返回false。
<?php echo addcslashes("zoo['.']", 'A..z')."\n"; echo stripcslashes("\z\o\o\['.'\]")."\n"; echo addcslashes("zoo['.']", 'z..A')."\n"; echo addslashes("what's this?")."\n"; echo addslashes("This is a NULL character: \x00")."\n"; echo bin2hex("Hello")."\n"; echo dechex(ord('H')).dechex(ord('e')).dechex(ord('l')).dechex(ord('l')).dechex(ord('o'))."\n"; echo chr(65)."\n"; echo chr(321)."\n"; echo convert_uuencode("hellophp"); echo convert_uudecode("(:&5L;&]P:'`` `")."\n"; echo hex2bin("48656c6c6f")."\n"; $orig = "\"hello\" <b>world</b>"; $a = htmlentities($orig); $b = html_entity_decode($a); echo $a."\n"; // "hello" <b>world</b> echo $b."\n"; // "hello" <b>world</b> $str = "\x8F!!!"; echo htmlentities($str, ENT_QUOTES, "UTF-8")."\n";//空字符串 echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8")."\n";//!!! $str = "<p><hello>"world"</p>\n"; echo htmlspecialchars_decode($str);//<p><hello>"world"</p> echo htmlspecialchars_decode($str, ENT_NOQUOTES);//<p><hello>"world"</p> echo htmlspecialchars("<p'hello'>world</p>", ENT_QUOTES)."\n";//<p'hello'>world</p> echo ord("2")."\n"; echo str_rot13("hello,world!")."\n"; echo str_rot13("uryyb,jbeyq!")."$n"; = "HelloWorld!\n"; echo quotemeta("hello?")."\n"; ?>
The above is the detailed content of What are the php string conversion functions?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.
