php去除字符串中數(shù)字的方法:首先創(chuàng)建一個(gè)PHP示例文件;然后使用正則表達(dá)式“$class=preg_replace("/\d+/",'', $res);”實(shí)現(xiàn)去除字符串中的數(shù)字即可。
推薦:《PHP視頻教程》
PHP去掉字符串中的數(shù)字
這個(gè)比較簡(jiǎn)單,但是也有些需要注意的地方,先貼代碼
$class=preg_replace("\d+",'', $res);
需要使用preg_replace函數(shù),但是只是這么寫的話,會(huì)報(bào)錯(cuò)
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash
翻譯過(guò)來(lái)就是定界符不能是字母數(shù)字或反斜線。
想了一下,在正則表達(dá)式首尾加了一對(duì)/
$class=preg_replace("/\d+/",'', $res);
這樣就成功了