【发布时间】:2018-09-24 16:24:50
【问题描述】:
我希望用替换而不是在双引号之间格式化一个句子。
例子,这句话:
$remplacement = ['the', 'in']; // words who must be deleted
$sentence = "the sea" OR the sea AND "the sea" in the world.
应该是:
“海”或“海”和“海”世界。
我认为我们可以使用 preg_replace 或 preg_match。 我找到了将文本放在双引号周围的正则表达式:
'/[^"]+(?=(?:[^"]*"[^"]*"[^"]*)*$)/'
【问题讨论】:
-
我们总是乐于帮助和支持新的编码员,但您需要先帮助自己。 :-) 在doing more research 之后,如果您有问题发布您尝试过的方法,并清楚地解释什么不起作用并提供a Minimal, Complete, and Verifiable example。阅读How to Ask 一个好问题。请务必take the tour 并阅读this。
-
未替换但已删除:)
标签: php regex preg-replace preg-match