It is possible to capture the menu or some special code
from a HTML source, without using REGEX.
[man]preg_match/man using regular expression is of course more effective.
Using [man]strpos/man or [man]stripos/man
and considerably more lines of code .....
Example. HTML to search inside:
......some html source
xxxxxx
<div id="menu">
<a href="...">link1</a>
<a href="...">link2</a>
<a href="...">link3</a>
</div>
<div id="main_contents">
abcdef
dfghjk
PHP. 'strpos_regex.php'
<?php // by halojoy March 2010
$html = '
......some html source
xxxxxx
<div id="menu">
<a href="...">link1</a>
<a href="...">link2</a>
<a href="...">link3</a>
</div>
<div id="main_contents">
abcdef
dfghjk';
// Define what we are looking for
$start = '<div id="menu">';
$end = '<div id="main_contents">';
// Search for start & end positions
$start_pos = strpos($html, $start);
$end_pos = strpos($html, $end);
$length = $end_pos - $start_pos;
// Cut out what is between start & end
$menu = substr($html, $start_pos, $length);
// Clean off leading/trailing spaces/newlines
$menu = trim($menu);
// Display or use the result
echo $html;
echo "\n<hr>\n";
echo $menu;
/* RESULT MENU OUTPUTS:
*************************
<div id="menu">
<a href="...">link1</a>
<a href="...">link2</a>
<a href="...">link3</a>
</div>
************************/
?>