有没有办法从 php 中的字符串中删除撇号? 示例:- 如果字符串是 Mc'win,那么它应该显示为 Mcwin
$Str = "Mc'win";
/*
some code to remove the apostrophe
*/
echo $Str; // should display Mcwin
最佳答案
您可以使用 str_replace。
$Str = str_replace('\'', '', $Str);
或
$Str = str_replace("'", '', $Str);
这会将 $Str
中的所有撇号替换为空(第二个参数)。第一个示例对撇号进行了转义,因此 str_replace 会将其识别为要替换的字符,而不是外壳的一部分。
关于php - 使用php从字符串中删除撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25256341/