generally, its better to user string functions, like substr and strpos rather then regular expressions (whenever you can) as the regular expression will take longer to evaluate.
The following function (
http://us3.php.net/preg_match) will do the trick:
[PHP]function ExtractString($str, $start, $end)
{
$str_low = strtolower($str);
$pos_start = strpos($str_low, $start);
$pos_end = strpos($str_low, $end, ($pos_start + strlen($start)));
if ( ($pos_start !== false) && ($pos_end !== false) )
{
$pos1 = $pos_start + strlen($start);
$pos2 = $pos_end - $pos1;
return substr($str, $pos1, $pos2);
}
}[/PHP]
This can be used with a string like:
[PHP]
$html_content = '
<body>
<form method="post" action="script.php">
</form>
</body>';
[/PHP]
to find the string between <body> and </body>
[PHP]$match = ExtractString($html_content, '<body>', '</body>');[/PHP]
or even the action url:
[PHP]$match = ExtractString($html_content, 'action="', '"');[/PHP]
note: the function searches for the end tag in a position after the start tag, so it will work in the second example fine.
www.digital-ether.com