You can try something like this to extract all the invoice numbers:
<?php
$input = "<body>
<p>Invoice ID: 0201</p>
<p>MID : Q987</p>
<p>Desciption: Solid Concrete Blocks</p>
<p>Qty: 7478 Blocks </p>
<p> </p>
<p>Invoice ID: 0324</p>
<p>MID : Q443</p>
<p>Desciption: Window Slides with Chrome </p>
<p>Qty: 33 Units </p>
</body>";
$invoice_ids = array();
if(preg_match_all('{<p>Invoice ID:\s*(\d+)</p>}',$input,$matches)) {
$invoice_ids = $matches[1];
}
var_dump($invoice_ids);
?>
Output:
array(2) {
[0]=>
string(4) "0201"
[1]=>
string(4) "0324"
}
Once you have extracted all the invoice numbers you can insert them in a database table using something like:
<?php
$con = mysql_connect("localhost","USRNAME","PASSWD");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("DB_NAME", $con);
foreach($invoice_ids as $id) {
$query = "INSERT INTO YOUR_TABLE_NAME(invoice_num) VALUES $id";
if(!mysql_query($query,$con)) {
die('Error: ' . mysql_error());
}
}
mysql_close($con)
?>