我想从字符串中删除单引号,但不删除作为撇号的引号。
例如:
请点击“此处”选择您要登录的帐户
我需要它像
请点击此处选择您要登录的帐户
我试过这个
$text = preg_replace( '/[^\da-z ! ?.]/i', ' ', $text );
但它删除了所有单引号。任何帮助赞赏。长时间搜索后,在堆栈溢出中找不到任何解决方案。
答案 0 :(得分:3)
模式:/\B'|'\B/
代码:(Demo)
$text="Please click 'here' to choose the account you'd like to 'Login'";
$text = preg_replace("/\B'|'\B/",'', $text);
echo $text;
输出:
Please click here to choose the account you'd like to Login
要处理多个所有格名词(或我们称之为的任何名词),例如girls' dresses
,这是一个更强大的调用:
代码:(Demo)(Pattern Demo)
$text="Please click 'here' to choose the users' accounts that you'd like to 'use'";
$text = preg_replace("/\B'([a-z-]+)'\B/i",'$1', $text);
echo $text;
输出:
Please click here to choose the users' accounts that you'd like to use