Home > Backend Development > PHP Tutorial > PHP implementation code for adding slash before special characters_PHP tutorial

PHP implementation code for adding slash before special characters_PHP tutorial

WBOY
Release: 2016-07-21 15:26:17
Original
858 people have browsed it

Copy code The code is as follows:

$zongzi = "asdfasdf(asdfasdf?asfdadsf)";
echo $zongzi = quotemeta($zongzi);
echo "
";
$zongzi = stripslashes($zongzi);
echo $zongzi;
?>


PHP quotemeta() function
Definition and usage
quotemeta() function adds a backslash before certain predefined characters in a string .

These predefined characters are:

Period (.)
Backslash ()
Plus sign (+)
Asterix (*)
Question mark (?)
Square brackets ([])
Caret (^)
Dollar sign ($)
Parentheses (())
Syntax
quotemeta(string)
参数 描述
string 必需。规定要检查的字符串。
Tips and Notes
Tips: This function can be used to escape characters with special meanings, such as ( ), [ ] and * in SQL.
Copy code The code is as follows:

$str = "Hello world. (can you hear me?)";
echo quotemeta($str);
?>

Output:
Hello world. (can you hear me?)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323994.htmlTechArticleCopy the code as follows: ?php $zongzi = "asdfasdf(asdfasdf?asfdadsf)"; echo $zongzi = quotemeta ($zongzi); echo "br /"; $zongzi = stripslashes($zongzi); echo $zongzi; ? PHP quotem...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template