我试了很多preg_replace和preg_match代码,但我不能这样做。 我试图找到字符串包含+18,18+或(+18) 我无法解释,但你可以理解当看到我的代码。发现加上“+”字符的数字像+90 90+在字符串
//inputs
$product='example: 18 kg apple'; // my hope output: EVERYONE
$product='water pipe (18) meters'; // my hope output: EVERYONE
//outputs: OVER 18
$product='product +18 dress'; // my hope output: OVER 18
$product='product 18+ dress'; // my hope output: OVER 18
$product='product (+18) dress'; // my hope output: OVER 18
//outputs are already OVER 18
//Because of contain 18
//not +18 or 18+. it doesnt work truly
preg_match('/\b(\w*18\w*)\b/', $product, $match);
if($match[1]=='+18' || $match[1]=='18+') {
echo "OVER 18<br>";
}
else{
echo "EVERYONE<br>";
}
尝试'preg_match('〜\ +18 \ b | \ b18 \ +〜',$ s,$ m)' –
它的工作原理非常感谢bro –