|
Posted by "Gustav Wiberg" on 10/09/05 18:04
Hi there!
I'm no good at reg exp... Yes, I confess..
Here's my code
<?php
$lines = file('export/nhExportVarupiraten.txt');
// Loop through our array, show HTML source as HTML source; and line numbers
too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
if ($line_num > 0 ) {
$getName = explode('<>', $line);
$pattern = "/ID=([0-9]*)\</";
$subject = $line;
$idNumber = preg_split($pattern, $subject);
echo "NAME = " . $getName[2] . " has ID number=$idNumber[0]<br>";
}
//require("phpfunctions/opendb.php");
//$sql = "UPDATE beskrivandeVarunamn=" . safeQuote($bNamn) . " WHERER"
//mysql_close();
}
?>
Output of this code is something like this:
Line #0 : Varupiraten<>http://www.varupiraten.se/ NH01<><>Liteon
DVD±RW<>1225<>http://www.varupiraten.se/web/spec_product.php?ID=2252<>PC-CD-DVD-LDW-SOHW-852SX<>0<>
Line #1 : NH01<><>LiteOn DVD±RW 16
x<>655<>http://www.varupiraten.se/web/spec_product.php?ID=2251<>PC-CD-DVD-LDW-1653S-01C<>1<>
NAME = LiteOn DVD±RW 16 x has ID number=NH01<><>LiteOn DVD±RW 16
x<>655<>http://www.varupiraten.se/web/spec_product.php?
Line #2 : NH01<><>LiteOn DVD±RW
8x<>599<>http://www.varupiraten.se/web/spec_product.php?ID=1708<>PC-CD-DVD-LDW-832S-11C<>1<>
NAME = LiteOn DVD±RW 8x has ID number=NH01<><>LiteOn DVD±RW
8x<>599<>http://www.varupiraten.se/web/spec_product.php?
Line #3 : NH01<><>LiteOn DVD±RW
16<>725<>http://www.varupiraten.se/web/spec_product.php?ID=1711<>PC-CD-DVD-LDW-1653S-09C<>1<>
NAME = LiteOn DVD±RW 16 has ID number=NH01<><>LiteOn DVD±RW
16<>725<>http://www.varupiraten.se/web/spec_product.php?
Line #4 : NH01<><>LITEON
8x<>725<>http://www.varupiraten.se/web/spec_product.php?ID=2250<>CD-DVD-LDW-811S<>1<>
NAME = LITEON 8x has ID number=NH01<><>LITEON
8x<>725<>http://www.varupiraten.se/web/spec_product.php?
Just focus on $idNumber[0] in the code above... In the last row I get an
output of LITEON 8x<>725<>http://www.varupiraten.se/web/spec_product.php?
I want to get an output of 2250. I do I achieve that?
/G
http://www.varupiraten.se/
Navigation:
[Reply to this message]
|