You can use PHP's regular expression functionality to match numbers with two or more digits in a title. Here is a simple example:
$title = "1341响应式照明灯饰壁灯企业网站模板";
$pattern = "/\d{2,}/"; // 匹配两位数及以上的数字
preg_match($pattern, $title, $matches);
echo $matches[0]; // 输出 "1341"In this example, we use the `preg_match` function, which takes three parameters: a regular expression pattern, an input string, and a variable name for storing the matching result. The regular expression pattern ` "/\d{2,}/" ` matches two or more digits. \d Matches any numeric character.{2,} Matches two or more numeric characters.
By using the `preg_match` function and storing the matching results in $matches In an array, we can easily extract two-digit or larger numbers from a title. In this example,$matches[0] Stores the first matching string – namely, "1341" from the title. If the title contains multiple matches, this function can be used. $matches[1]、$matches[2] Wait until you can obtain them.
Note that this example only matches the first two-digit or longer number in the title. If you need to match all such numbers in the title, you can use the `preg_match_all` function. For example:
$title = "1341响应式照明灯饰壁灯企业网站模板";
$pattern = "/\d{2,}/"; // 匹配两位数及以上的数字
preg_match_all($pattern, $title, $matches);
print_r($matches[0]); // 输出 Array([0] => 1341)In this example, we use the `preg_match_all` function; this function is similar to the `preg_match` function, but it can match all occurrences. In this example,$matches[0] Contains all matched strings, i.e., "1341". Since there is only one match in this example, the array contains a single element. If there are multiple matches in the title, the array will contain multiple elements, each representing one match.