<?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.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
- 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
)
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
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:
185.93 ms | 403 KiB | 183 Q