Are you aware that the regex argument to any of PHP's preg_
functions has to be double-delimited? For example:
preg_match_all(`'/foo/'`, $target, $results)
'...'
are the string delimiters, /.../
are the regex delimiters, and the actual regex is foo
. The regex delimiters don't have to be slashes, they just have to match; some popular choices are #...#
, %...%
and ~...~
. They can also be balanced pairs of bracketing characters, like {...}
, (...)
, [...]
, and <...>
; those are much less popular, and for good reason.
If you leave out the regex delimiters, the regex-compilation phase will probably fail and the error message will probably make no sense. For example, this code:
preg_match_all('<td style="white-space:nowrap;">###.##</td>', $s, $m)
...would generate this message:
Unknown modifier '#'
It tries to use the first pair of angle brackets as the regex delimiters, and whatever follows the >
as the regex modifiers (e.g., i
for case-insensitive, m
for multiline). To fix that, you would add real regex delimiters, like so:
preg_match_all('%<td style="white-space:nowrap;">###\.##</td>%i', $s, $m)
The choice of delimiter is a matter of personal preference and convenience. If I had used #
or /
, I would have had to escape those characters in the actual regex. I escaped the .
because it's a regex metacharacter. Finally, I added the i
modifier to demonstrate the use of modifiers and because HTML isn't case sensitive.