[thelist] regexp problem

Mark Kennedy mark at eurogamer.net
Thu Jul 8 03:08:24 CDT 2004


Hi Alex,

> preg_match_all("<a[^>]*>.*?</a>", $theHtml, $matches);
> gives this error:
>
> *Warning*: Unknown modifier ']'

Read:

http://uk2.php.net/manual/en/function.preg-match.php

And note how the examples form their expressions.  They all start with 
'/' and are terminated with a '/' optionally followed by a modifier 
(such as 'i' which makes the match case insensitive).

To make your pattern work, use:

"/<a[^>]*>.*?<\/a>/"

Note that I've escaped the '/' in '</a>'

Technically, you can use anything as a start and finish marker for your 
pattern, as long as it's the first thing that appears.  You could avoid 
escaping the '/' in </a> by using '|' as a delimiter.  However, it seems 
to have become common practice to use '/' these days, and that's what 
most examples you'll see will use.

Hope that helps.  Always remember to read the PHP manual -- it's excellent!

Mark



More information about the thelist mailing list