preg_match在'Hifi Reg Tester'中工作,但在代码中返回'false'

时间:2021-08-19 18:09:51

Sorry to ask a so simple question but here is my problem. I'm actually modifying the PlancakeEmailParser to fit my needs.

很抱歉问一个这么简单的问题,但这是我的问题。我实际上正在修改PlancakeEmailParser以满足我的需求。

I made a simple regex :

我做了一个简单的正则表达式:

/([^:]+) (<+.*>)$/

that should match with :

应符合:

John DOE <johndoe@fakemail.com>

I tested it in http://www.gethifi.com/tools/regex it works perfectly

我在http://www.gethifi.com/tools/regex上进行了测试,它完美无缺

But in my code it returns false !

但在我的代码中,它返回false!

Here is the offending code :

这是违规代码:

preg_match('/([^:]+): ?(.*)$/', $line, $matches);
$newHeader = strtolower($matches[1]);

$string = $matches[2];
$reg = "/([^:]+) (<+.*>)$/";

echo 'VALUE: '.$string."\n";
echo 'PREG_MATCH: '.preg_match($reg, $string)."\n\n";

if (preg_match('/([^:]+) (<+.*>)$/', $matches[2])) {
    echo('match'."\n\n\n\n");
} else {
    $value = $matches[2];
}

Here is the echo feedback :

这是回声反馈:

VALUE: John DOE <johndoe@fakemail.com>
PREG_MATCH: 0

Does anyone of you understand what is the problem ?

你有谁知道这是什么问题?

Thank you very much !

非常感谢你 !

EDIT

The problem was that I made an htmlentities on the all content, so the <> where converted.

问题是我对所有内容都做了很多,所以转换的<>。

The solution is to rewrite the regex from this :

解决方案是从这里重写正则表达式:

/([^:]+) (<+.*>)$/

to this

/([^:]+) (&lt;+.*&gt;)$/

Thank you very much Peter Alfvin for tryin to help :)

非常感谢Peter Alfvin试着帮助:)

Maybe it could help someone someday

也许有一天它可以帮助某人

1 个解决方案

#1


0  

SOLVED The problem was that I made an htmlentities on the all content, so the <> where converted. The solution is to rewrite the regex from this :

解决了问题是我对所有内容都做了很多,所以转换的<>。解决方案是从这里重写正则表达式:

/([^:]+) (<+.*>)$/ to this /([^:]+) (&lt;+.*&gt;)$/

or remove the htmlentities from all content and use it only when needed, which I finally did !

或从所有内容中删除htmlentities并仅在需要时使用它,我终于做到了!

Maybe it could help someone someday...

也许有一天它可以帮助某人......

#1


0  

SOLVED The problem was that I made an htmlentities on the all content, so the <> where converted. The solution is to rewrite the regex from this :

解决了问题是我对所有内容都做了很多,所以转换的<>。解决方案是从这里重写正则表达式:

/([^:]+) (<+.*>)$/ to this /([^:]+) (&lt;+.*&gt;)$/

or remove the htmlentities from all content and use it only when needed, which I finally did !

或从所有内容中删除htmlentities并仅在需要时使用它,我终于做到了!

Maybe it could help someone someday...

也许有一天它可以帮助某人......