Great! It works! Thank you very much.
Also thanks to all the other guys who answered. I also think I finally
started to understand these regular expressions a bit better.
- Morten
- Original Message -
From: "Richard Lynch" <[EMAIL PROTECTED]>
To: "Morten Twellmann" <[EMAIL PROTECTED]>
Cc:
Sent: Monday, October 16, 2006 7:42 PM
Subject: Re: [PHP] Regular expressions
> On Sat, October 14, 2006 4:19 pm, Morten Twellmann wrote:
> > I'm trying to understand these regular expressions, but I can't make
> > them
> > work...
> >
> > All I want to do, is to find the first occurrence of some text inside
> > the
> > HTML tags and .
> >
> > Example string: "October 14, 2006Welcome to my
> > homepageWe're happy to announce..."
> >
> > must return:
> >
> > "Welcome to my homepage"
> >
> >
> > I tried with:
> >
> > preg_match(']*>(.*?)', "Welcome to my homepage",
> > $matches, PREG_OFFSET_CAPTURE);
> > print_r($matches);
> >
> > but got nothing...
> >
> > Can anyone tell me how to do this?
> >
> > (I tried the above expression in EditPad Pro 6 and it worked...!)
>
> Download "The Regex Coach" and play with that -- It's not 100% the
> same as PHP, and the escaping of backslashes for PHP isn't in it, but
> it rocks for visual presentation of pattern/match
>
> Your main problem is a lack of start/end delimiters for the pattern:
> '|]*>(.*)|ims'
> would probably be better.
> | at beginning/end as pattern delimiters
> i becase H1 and h1 are both the same tag in HTML
> ms because newlines inside the text are okay
> Take out the \b because I dunno what it does, but you don't need it.
> .*? is kinda silly -- .* mean "0 or more characters", and ? means
> "maybe" but putting them together has no added value, so lose the ?
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some starving artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php