php method to use regular numbers to replace numbers: first create a PHP sample file and set the file encoding; then use "preg_replace($reg, $after, $str);" to implement the function of regular number replacement; Finally execute the file.
Recommended: "PHP Video Tutorial"
<?php header("Content-type: text/html; charset=utf8"); $str = "我的QQ号是43247943,身高是175厘米,体重是69.5公斤,年龄二十五岁"; echo $str . '<br>'; $reg = '/((0|[1-9]\d*)(\.\d+)?)|(零|一|二|三|四|五|六|七|八|九|十)(百|十|零)?(一|二|三|四|五|六|七|八|九)?(百|十|零)?(一|二|三|四|五|六|七|八|九)?/'; $after = '***'; $newstr = preg_replace($reg, $after, $str); echo $newstr . '<br>';
Output results
Regular expression matching Chinese numbers
$rule='/(零|一|二|三|四|五|六|七|八|九|十)(百|十|零)?(一|二|三|四|五|六|七|八|九)?(百|十|零)?(一|二|三|四|五|六|七|八|九)?/';
The above is the detailed content of How to use regex to replace Chinese numbers in php. For more information, please follow other related articles on the PHP Chinese website!