my end goal is to show an invoice with data of the customer, therefor i made a templatefile with pure html and within a function, i get the content of the templatefile and replace specific words in the templatefile with the data of the customer. so far so good.
but now, i have a repeatitive part of the templatefile, the one with the bought items.. my idea is to substract that specific part out of the variable with the content of the templatefile, duplicate and fill it with a while loop and put it back in the variable, replacing the original.. (hopefully your still with me?)
this works:
$url = $_SESSION['dir'].'php/invoice.php';
$invoice = file_get_contents($url);
//replace data
$replacement = array("name", "prefix", "ordernumber", "orderdate", "address", "zipcode", "place", "country", "ordername", "orderaddress", "orderzipcode", "orderplace", "ordercountry");
foreach ($replacement as $word){
$invoice = str_replace('{$'.$word.'}', $data[$word], $invoice);
}
so the whole invoice code is in $invoice and the data of the customer is allready in it
now time for the next step: the substraction of the specific part, which is between these tags: <!-- repeat --> <!-- /repeat -->
i was thinking of:
preg_match("/<!-- repeat -->(.*)<!-- \/repeat -->/", $invoice, $invoicepart);
but that does not work.. is that because the syntax is wrong or because the part to select excists of a lot of html code?
after that, i was think of:
$itemresult = item_query();
while ($itemrow = mysql_fetch_array($itemresult)){
//replace item data
$temporalpart = $invoicepart;
$replacement = array("itemname", "itemamount", "itemprice", "itempricetotal");
foreach ($replacement as $word){
$temporalpart= str_replace('{$'.$word.'}', $itemrow[$word], $temporalpart);
}
$newinvoicepart.= $temporalpart
}
$invoice = str_replace("$invoicepart", "$newinvoicepart", "$invoice");
would that be the right way to go further?
many thanks for helping me!