i use preg_mach for extract some html ( i try to use DOMDocument but i had some problem with new line )
any way … that’s my code ..
1.html
<body>
<!-- icon and title -->
<div class="smallfont">
<img class="inlineimg" src="images/icons/icon1.gif" alt="" border="0" />
<strong>qrtoobah 3nwan</strong>
</div>
<hr size="1" style="color:#CCCCCC; background-color:#CCCCCC" />
<!-- / icon and title -->
<div id="post_message_14142536">
<font size="7"><font color="red">msaha 700</font></font><br />
<font size="7"><font color="red">shamali 20</font></font><br />
<font size="7"><font color="red"> 1700 almetr</font></font><br />
<font size="7"><font color="#ff0000">sooom bs</font></font><br />
<font size="7"><font color="#ff0000">albee3 qreeb</font></font>
</div>
<!-- message -->
</body>
extract.php
<?php
$html = file_get_contents("1.html");
$pattern = '/<([!]+)([^]+).*>([^]+)(message\ \-\-\>)/';
preg_match($pattern, $html, $matches);
print_r($matches);
?>
i want to get any thing between <!-- icon and title -->)blablabla(<!-- / message -->…
but i get that array :
Array ( [0] => [1] => ! [2] => -- [3] => message --> )
Use
strposto find first tag position. Then find ending tag also withstrpos. I mean – if u know from where to what you are looking for and they are unique.. so what matter inpreg_*functions?So i guess something like this will work fine (I make code clear as possible for understanding my idea in step-by-step actions):
Also u can do exactly the same if u want find and store all structures between opening
<!-- (.*) -->and closing<!-- / (.*) -->.Only change u must do – first find with preg_match all opening structures names. For example:
After that one-loop for $openings and find with code above all needed. just adding to openings closing “/” chacter in right place.