Re: Regular expressions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 14 Oct 2006 23:19:13 +0200, "Morten Twellmann" <morten@xxxxxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux