所以我试图替换文本中的所有'
并将其替换为php中的'
我有一个变量$desc = "he's such a good person and he'll be very successfull";
我正在尝试执行以下操作
$desc = str_replace("'","'",$desc);
但在str_replace
中使用正则表达式是否有办法成功?
是的,现在看起来很好......出于某种原因。
有没有办法使用正则表达式?
例如从文本中删除html标签?
$desc = "<strong> he's such a good person </strong> <br /> he'll be very successfull";
$desc = str_replace("<*>"," ",$desc);
答案 0 :(得分:2)
您可以尝试使用正确的PHP函数来完成这项工作,因此请查看:preg_replace
doc。
在你的情况下,你想这样使用:
preg_replace('/'/', "'", $desc);
看看这个执行: https://eval.in/800948
答案 1 :(得分:0)
它是否必须是正则表达式,因为这是一种更简单的方法
$desc = "he's such a good person and he'll be very successfull";
$new = str_replace(''', "'", $desc);
echo $new;
结果:
he's such a good person and he'll be very successfull
答案 2 :(得分:0)
您不需要使用正则表达式,因为它会更复杂 使用
$desc = "he's such a good person and he'll be very successfull";
$desc = str_replace("'","'",$desc);
echo "after replace :"." ".$desc;
它更简单:)