2 回答

TA貢獻(xiàn)1887條經(jīng)驗 獲得超5個贊
使用正則表達(dá)式:
preg_match('/^\D*\d(.*)/', 'hello12cool4here', $matches);
echo($matches[1]); // 2cool4here
preg_match('/^\D*\d(.*)/', 'hel3lo12cool4here', $matches);
echo($matches[1]); // lo12cool4here
preg_match('/^\D*\d(.*)/', '42lo12cool4here', $matches);
echo($matches[1]); // 2lo12cool4here

TA貢獻(xiàn)1827條經(jīng)驗 獲得超8個贊
您可以遍歷所有字符并測試它們是否為數(shù)字,找到第一個時返回:
$str='hello12cool4here';
for( $i=0; $i< strlen( $str ); $i++ ){
if( is_numeric( substr($str,$i,1) ) )exit( substr( $str, $i+1 ) );
}
或?qū)⑵浞湃牒瘮?shù)中:
function findremainder( $str ){
for( $i=0; $i< strlen( $str ); $i++ ){
if( is_numeric( substr($str,$i,1) ) )return( substr( $str, $i+1 ) );
}
return $str;
}
echo findremainder( $str );
- 2 回答
- 0 關(guān)注
- 94 瀏覽
添加回答
舉報