[英]change string in php after getting it from mysql database
I have following data: 我有以下数据:
$var = $_POST['name'];
then $var="jay's Box"
change to: 改成:
$var = "jay\'s box"
How to do that? 怎么做?
You can use addslashes()
function 您可以使用addslashes()
函数
$var = addslashes($var);
More information at http://php.net/manual/en/function.addslashes.php . 有关更多信息,请参见http://php.net/manual/zh/function.addslashes.php 。
Just a note , the opposite of this function is stripslashes()
. 仅需注意 ,此函数的反义是stripslashes()
。
Hope this helps, thanks! 希望这会有所帮助,谢谢!
Take a look at addslashes() 看一看addslashes()
<?php
$quote = "Jay's Box";
print_r(addslashes($quote));
?>
http://php.net/manual/en/function.addslashes.php http://php.net/manual/en/function.addslashes.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.