read from html file using php
Posted: Thu Jul 14, 2011 8:54 am
I need to extract the image and corresponding page number using php . i used regular expression and got the image name . but i need to get the number befor that eg 1 and 343
my code
$myFile = 'Dome-Tome1-StephenKings.html';
$content = file($myFile);
// how many lines in this file
$numLines = count($content);
echo $numLines;
// process each line
for ($i = 0; $i < $numLines; $i++) {
// use trim to remove the carriage return and/or line feed character
// at the end of line
$line = trim($content[$i]);
preg_match_all('/<img .*src=["|\']([^"|\']+)/i', $line, $matches);
foreach ($matches[1] as $key=>$value) {
echo $value."<br>";
}
}
output
-----------
Dome-Tome1-StephenKing-1_1.jpg
Dome-Tome1-StephenKing-343_1.jpg
I need this output
--------------------
1
Dome-Tome1-StephenKing-1_1.jpg
343
Dome-Tome1-StephenKing-343_1.jpg
somebody please help
Html code
----------------------------
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<A name=1></a><IMG src="Dome-Tome1-StephenKing-1_1.jpg"><br>
<hr>
<A name=2></a>© …ditions Albin Michel, 2011<br>
pour la traduction franÁaise<br>
ISBN : 978-2-226-22437-8<br>
<hr>
<A name=3></a>Aux …ditions Albin Michel<br>
D‘ME, tome 1, 2011<br>
<hr>
<A name=4></a><hr>
<A name=5></a>SEL<br>
<hr>
<A name=6></a>1<br>
Les deux femmes ..... etc
<A name=343></a><IMG src="Dome-Tome1-StephenKing-343_1.jpg"><br>
ressemblait tel ement ‡ etc
</BODY>
</HTML>
my code
$myFile = 'Dome-Tome1-StephenKings.html';
$content = file($myFile);
// how many lines in this file
$numLines = count($content);
echo $numLines;
// process each line
for ($i = 0; $i < $numLines; $i++) {
// use trim to remove the carriage return and/or line feed character
// at the end of line
$line = trim($content[$i]);
preg_match_all('/<img .*src=["|\']([^"|\']+)/i', $line, $matches);
foreach ($matches[1] as $key=>$value) {
echo $value."<br>";
}
}
output
-----------
Dome-Tome1-StephenKing-1_1.jpg
Dome-Tome1-StephenKing-343_1.jpg
I need this output
--------------------
1
Dome-Tome1-StephenKing-1_1.jpg
343
Dome-Tome1-StephenKing-343_1.jpg
somebody please help
Html code
----------------------------
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<A name=1></a><IMG src="Dome-Tome1-StephenKing-1_1.jpg"><br>
<hr>
<A name=2></a>© …ditions Albin Michel, 2011<br>
pour la traduction franÁaise<br>
ISBN : 978-2-226-22437-8<br>
<hr>
<A name=3></a>Aux …ditions Albin Michel<br>
D‘ME, tome 1, 2011<br>
<hr>
<A name=4></a><hr>
<A name=5></a>SEL<br>
<hr>
<A name=6></a>1<br>
Les deux femmes ..... etc
<A name=343></a><IMG src="Dome-Tome1-StephenKing-343_1.jpg"><br>
ressemblait tel ement ‡ etc
</BODY>
</HTML>