在 PHP 中,给定一段长文本,例如:
Ms. Kane, who was elected attorney general last year and has been mentioned as a possible future candidate for governor, struck a political note in her brief announcement to an audience that cheered and applauded her decision.
“我是这样看的,州长会没事的,”她说。她补充说,她想知道谁将代表“戴夫和罗比,谁代表艾米丽和艾米?”</p>
“作为司法部长,”她说,“我选择你。”</p>
我想提取所有引用的材料,在这种情况下是一个包含这些结果的数组:
"I looked at it this way, the governor’s going to be O.K.,"
"the Daves and Robbies, who represents the Emilys and Amys?"
"As attorney general,"
"I choose you."
假设:
- 总会有一个匹配的开盘价和收盘价
- 简单的双引号
如果您还确保它可以处理弯引号、单引号和其他特殊情况,则可以加分,但如果这样更容易,请随意假设纯双引号。
是的 - 我已经在网站上搜索了答案,虽然有些东西看起来很有帮助,但我没有找到任何有用的东西。最接近的是这个但没有骰子:
preg_match_all('/"([^"]*(?:\\"[^"]*)*)"/', $content, $matches)