Home  >  Article  >  Backend Development  >  Detailed explanation of addcslashes() function in PHP

Detailed explanation of addcslashes() function in PHP

autoload
autoloadOriginal
2021-05-08 15:22:352178browse

Detailed explanation of addcslashes() function in PHP

The previous article told you about "How to understand foreach traversing a two-dimensional array in php". This article mainly talks about php The addcslashes() function in. In the actual use of

php, we may need to escape some characters in the string. At this time, we need to use the php Built-in function addcslashes() function, this article will take you to take a look.

addcslashes    ( string $str   , string $charlist   )
  • $str: Characters to be escaped

  • $charlist: Characters or character range to be escaped.

  • Return value: escaped characters.

Code example:

<?php 
$str = "Welcome to php.cn!"; 
echo $str."<br>"; 
echo addcslashes($str,&#39;n&#39;)."<br>"; 
echo addcslashes($str,&#39;h&#39;)."<br>"; 
?>
输出:
Welcome to php.cn!
Welcome to php.c\n!
Welcome to p\hp.cn!

Recommended: 2021 PHP interview questions summary (collection) 》《php video tutorial

The above is the detailed content of Detailed explanation of addcslashes() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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