在php中强制删除双引号和单引号

在php中强制删除双引号和单引号,php,string,preg-replace,Php,String,Preg Replace,在将单引号和双引号插入数据库中的表之前,如何在检测到它们时强制删除它们?每当我读取数据库中带有引号和单引号的数据时,我都会遇到问题 这是我尝试过的代码 <?php $string = "sample 'word' with a quotation"; $string = preg_replace("/<!--.*-->/", "", $string); echo $string; ?> 从字符串中去掉引号不是处理引号的方法。您应该通过转义它们或使用准备好的语句将它们插入

在将单引号和双引号插入数据库中的表之前,如何在检测到它们时强制删除它们?每当我读取数据库中带有引号和单引号的数据时,我都会遇到问题

这是我尝试过的代码

<?php
$string = "sample 'word' with a quotation";
$string = preg_replace("/<!--.*-->/", "", $string);
echo $string;
?>

从字符串中去掉引号不是处理引号的方法。您应该通过转义它们或使用准备好的语句将它们插入数据库来适当地处理它们。几乎可以肯定,任何其他做法都是非常糟糕的。
$string = "sample 'word' with a quotation";
$string = str_replace(array("'",'"'), "", $string);
echo $string; // sample word with a quotation