Re: FN-FORUM: php pattern
date posted 12th November 2007 19:24
On Mon, 2007-11-12 at 20:01 +0000, Derek Almond wrote:
> I've gone code blind, for the snippet below, Why aren't my patterns
> matching?
>
> preg_match("/Location\s*.*.* class=\"Small\">(.*)/smiU", $data, $matches);
> preg_match("/Salary\/Rate\s*.* class=\"JSDR\">.*(.*)/smiU", $data, $matches);
>
>
Haven't checked this, but try replacing the '.*' in
.*
with '.*?'
.*?
Otherwise, I think, it will match to the furthest in the line,
when you want the nearest one.
To me, this looks a painful way to parse a piece of html. Have you
considered using a Dom model or suchlike instead?
Graham
>
> $data contains....
>
>
> Location:
>
> City, London
>
>
>
> Type:
>
> Contract
>
>
>
> Salary/Rate:
>
> 350-400/Day
>
>
>
> Cheers
>
> D
>
>