【问题标题】:PHP Regex preg_match won't work [closed]PHP Regex preg_match 不起作用[关闭]
【发布时间】:2026-02-24 22:00:01
【问题描述】:
if (preg_match("/<response>(.*)<\/response>/iUms", '<response>CONNECTED_OK</response>', $mathces))
{
    var_dump($matches);
}

我试过这个,但起初我有一个带有 cURL 的下载页面,现在我已经硬编码了这个主题。我尝试了很多其他的东西,但它总是返回带有 null 的 $matches。

【问题讨论】:

  • 你确实有一个错字,是复制过来的

标签: php regex preg-match


【解决方案1】:

试试这个:

if (preg_match("/<response>(.*)<\/response>/iUms", '<response>CONNECTED_OK</response>', $matches)) { var_dump($matches); }

你有$mathces而不是$matches

【讨论】:

  • 该死,好吧...我想我今天已经编码太多小时了。该睡了。但是非常感谢!
  • @user3788436 不,这与您编码的时间无关。这与您没有打开错误报告有关。