The following preg_match call returns null within a WordPress code:
preg_match('/(<div class="title-primary">)([^<]*)(</div>)/', $content, &$matches)
Even if the input contains: <div class="title-primary"> bla-bla </div>
.
There are no PHP errors.
This works well when tested with online tools:
Result:
Array
(
[0] => <div class="title-primary">
bla-bla </div>
[1] => <div class="title-primary">
[2] =>
bla-bla
[3] => </div>
)
Any idea what might be the problem?
This indeed works well when testing with online tools or my own environment. Submitted at http://phptester.net/
Result:
Which means that it must be something else in your code that prevents this from running properly. First thing that I would look at would be why you are using pass-by-reference operator with $matches – is there a chance that $matches gets over-written somewhere in between the preg_match and the point at which you are debugging the code?