are*_*iyw 0 php string str-replace
如何减少我的str_replace php代码?
我想删除aass直到zass
这是我的PHP代码,它的工作正常.但我想减少.我能怎么做 ?
<?PHP
$str = str_replace('aass', '', $str);
$str = str_replace('bass', '', $str);
$str = str_replace('cass', '', $str);
$str = str_replace('dass', '', $str);
$str = str_replace('eass', '', $str);
$str = str_replace('fass', '', $str);
$str = str_replace('gass', '', $str);
$str = str_replace('hass', '', $str);
$str = str_replace('iass', '', $str);
$str = str_replace('jass', '', $str);
$str = str_replace('kass', '', $str);
$str = str_replace('lass', '', $str);
$str = str_replace('mass', '', $str);
$str = str_replace('nass', '', $str);
$str = str_replace('oass', '', $str);
$str = str_replace('pass', '', $str);
$str = str_replace('qass', '', $str);
$str = str_replace('rass', '', $str);
$str = str_replace('sass', '', $str);
$str = str_replace('tass', '', $str);
$str = str_replace('uass', '', $str);
$str = str_replace('vass', '', $str);
$str = str_replace('wass', '', $str);
$str = str_replace('xass', '', $str);
$str = str_replace('yass', '', $str);
$str = str_replace('zass', '', $str);
?>
Run Code Online (Sandbox Code Playgroud)
使用正则表达式:
$res = preg_replace('~[a-z]ass~', '', $str);
Run Code Online (Sandbox Code Playgroud)
该[a-z]字符类匹配任何小写ASCII字母.
请参阅正则表达式演示.
| 归档时间: |
|
| 查看次数: |
101 次 |
| 最近记录: |