I have here sample.txt that contains
<a href="http://www.localhost/"></a>
<a href="http://www.localhost1/"></a>
<a href="http://www.localhost2/" class="class_name"></a>
here is my php code
<?
$mainUrl = "sample.txt";
$mainHtml = '';
$mainRemote = @fopen($mainUrl,'r');
while(!feof($mainRemote))
$mainHtml .= fread($mainRemote,10240);
fclose($mainRemote);
$num = preg_match_all('/("http:\/\/www.)(.*)(.")/i',$mainHtml,$mainCode);
$x=0;
foreach($mainCode[0] as $m => $mm) {
$x++;
if (($x <= $num)){
echo "Line #<b>{$m}</b> : ".htmlspecialchars($mainCode[0][$m])."<br>";
}
}
echo "<p>THERE ARE <h3>".$x."</h3> RESULTS<br>";
?>
the out put of this code is
Line #0 : "http://www.localhost/"
Line #1 : "http://www.localhost1/"
Line #2 : "http://www.localhost2/" class="class_name"
THERE ARE
3
RESULTS
My real objective is to have an output that looks like this
the out put of this code is
Line #0 : "http://www.localhost/"
Line #1 : "http://www.localhost1/"
Line #2 : "http://www.localhost2/"
THERE ARE
3
RESULTS
So if you don't notice the difference between the two output its the annoying
class="class_name"
I think my only problem is the patter inside my preg_match_all
preg_match_all('[FONT=Courier]/("http:\/\/www.)(.*)(.")/i[/FONT]',$mainHtml,$mainCode);
can anyone help me figure this out. please...
Thank you very much in advance