On Sat, 14 Oct 2006 23:19:13 +0200, "Morten Twellmann" <[EMAIL PROTECTED]> 
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 <h1> and </h1>.
> 
> Example string: "<p>October 14, 2006</p><h1>Welcome to my
> homepage</h1><p>We're happy to announce...</p>"
> 
> must return:
> 
> "Welcome to my homepage"
> 
> 
> I tried with:
> 
> preg_match('<h1\b[^>]*>(.*?)</h1>', "<h1>Welcome to my homepage</h1>",
> $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...!)
> 
> Sincerely,
> 
> Morten Twellmann

The regex you wrote lacks separator. That PHP statement will occur an
error:

> Warning: preg_match() [function.preg-match]: Unknown modifier ']' in
> /path/file.php on line X

The statement should be:

preg_match("/<h1\b[^>]*>(.*?)<\/h1>/i", "<h1>Welcome to my homepage</h1>",
$matches, PREG_OFFSET_CAPTURE);
print_r($matches);

--
Sorry for my poor English.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to