PHP - 摆脱卷曲撇号 [英] PHP - Getting rid of curly apostrophes
本文介绍了PHP - 摆脱卷曲撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ word =今天;
$ search = array('„','“','’');
$ replace = array('','','');
$ word = str_replace($ search,$ replace,htmlentities($ word,ENT_QUOTES));
我最终得到的是$ word包含'今天’ s'。
当我从$ search数组中删除&符号时,替换会发生,但这显然会并没有完成工作,因为&符号留在字符串中。为什么str_replace遇到和符号失败?
解决方案
为什么不这样做:
$ word = htmlentities(str_replace($ search,$ replace,$ word),ENT_QUOTES);
?
I'm trying to get rid of curly apostrophes (ones pasted from some sort of rich text doc, I imagine) and I seem to be hitting a road block. The code below isn't working for me.
$word = "Today’s";
$search = array('„', '“', '’');
$replace = array('"', '"', "'");
$word = str_replace($search, $replace, htmlentities($word, ENT_QUOTES));
What I end up with is $word containing 'Today’s'.
When I remove the ampersands from my $search array, the replace takes place but this, obviously, will not get the job done since the ampersand is left in the string. Why is str_replace failing when it comes across the ampersands?
解决方案
Why not just do this:
$word = htmlentities(str_replace($search, $replace, $word), ENT_QUOTES);
?
这篇关于PHP - 摆脱卷曲撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文