我遇到了一些问题,试图从php文档中插入一些数据,直到我得到2个包含引号的值,例如:
“充满星星”
id喜欢删除'空格或什至什么也没有。
->“ Rempli d etoiles”这是我尝试的方法:
$posdeapostrophe = strpos($array, '\'');
if ($posdeapostrophe == false)
{
...
}
else
{
// it goes in this block when it detects a ', but seems like trim doesnt work as i would
$newchaine = trim($array, '\'');
$sql .= "INSERT INTO categorie (id_cat,name_cat) VALUES (" . $cpt . ",'" .$newchaine . "'); ";
谢谢!
您可以使用str_replace()
。
$array = "Some string's";
$posdeapostrophe = strpos($array, "'");
$val = '';
if ($posdeapostrophe !== false)
{
$val = str_replace("'", "\'", $array);
}
echo $val;
也可以使用strpos()
和replace()
来代替单引号。
mysqli_real_escape_string($con, $array ); //for mysqli
mysql_real_escape_string($array , $con); //for mysql
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句