Welcome 微信登录

首页 / 网页编程 / PHP / php字符串的转义和还原

php字符串的转义和还原2016-08-28 本站 乖兔快跑1、手动转义和还原字符串

<?php

echo "select * from emp where name="张三"";

?>

输出:select * from emp where name="张三"

2、使用函数来转义和还原字符串

(1)addslashes()函数:用于为字符串加入反斜线“”

语法:

string addslashes(string str)

(2)stripslashes()函数:将使用addslashes()函数转义后的字符串返回原样

语法:

string striplsashes(string str)

例:

<?php
$str="select * from emp where name="张三"";
echo $str."<br />";
$a=addslashes($str);
echo $a."<br />";
$b=stripslashes($a);
echo $b."<br />";
?>
URL:http://www.bianceng.cn/webkf/PHP/201608/50401.htm