<?php
//$s = "--included-- in package price: 5 % vat aed 10.00 destination fee per night 2 % municipality fee 3.5 % packaging fee 10 % warranty service charge breakfast";
$s = "--included-- in product price: breakfast --excluded--: 5 % vat aed 10.00 destination fee per night 2 % municipality fee 3.5 % packaging fee 10 % warranty service charge";
$results = [];
if (preg_match_all('~(--(?:(?:not )?in|ex)cluded--)(?:\s+([a-zA-Z ]+))?:+\s*((?:(?!--(?:(?:not )?in|ex)cluded--).)*)~su', $s, $m, PREG_SET_ORDER, 0)) {
foreach ($m as $v) {
$lastline=array_pop($v); // Remove last item //print_r($details);
if (preg_match_all('~(?:(\b(?:usd|aed|mad|usd)\b|\B€|\bus\$)\s*)?\d+(?:\.\d+)?(?:(?!(?1))\D)*~u', $lastline, $details)) {
$results[] = array_merge($v, $details[0]);
} else {
$results[] = $v;
}
}
//[3] => 5 % vat aed [4] => 10.00 destination fee per night
//[3] => 5 % vat [4] => aed 10.00 destination fee per night
}
print_r($results);
- Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- Array
(
[0] => Array
(
[0] => --included-- in product price: breakfast
[1] => --included--
[2] => in product price
)
[1] => Array
(
[0] => --excluded--: 5 % vat aed 10.00 destination fee per night 2 % municipality fee 3.5 % packaging fee 10 % warranty service charge
[1] => --excluded--
[2] =>
[3] => 5 % vat
[4] => aed 10.00 destination fee per night
[5] => 2 % municipality fee
[6] => 3.5 % packaging fee
[7] => 10 % warranty service charge
)
)
preferences:
153.04 ms | 409 KiB | 5 Q