Forum Moderators: coopster

Message Too Old, No Replies

preg match all - help excluding html tag

         

joshm

7:52 am on Jul 17, 2008 (gmt 0)

10+ Year Member



Hello,

I am using preg_match_all to match some html code... it is matching fine but there's a part that isn't found as a match because it has a <br> tag in it - apart from that it's exactly like the pattern it's trying to match. I want it to exclude the <br> tag if it's found in the pattern. I tried something like: [<br>]? but it doesn't work. Any suggestions?

penders

8:54 am on Jul 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So you want it to match regardless of whether there is a <br> in the middle? The <br> is optional and can therefore appear either 0 or 1 times? May be you just need to:
(<br>)?

Rounded brackets (group) as opposed to square brackets. The square brackets denote a character class, so would match any *1* of the characters '<', 'b', 'r' or '>' which is made optional by the following '?'

[edited by: eelixduppy at 11:58 am (utc) on July 17, 2008]
[edit reason] disabled smileys [/edit]

joshm

10:20 am on Jul 17, 2008 (gmt 0)

10+ Year Member



Thanks, that fixed it.