PHP 将字符串中的数字转化为数组


$str ='现在是2019年11月18日下午17点25分';
$result='';
$arr=[];
for($i=0;$i<strlen($str);$i++){
if(is_numeric($str[$i])){
$result.=$str[$i];
}else{
if($result!="") {
$arr[] = $result;
$result="";
}
}
}


打印数据:

  Array
  (
    [0] => 2019
    [1] => 11
    [2] => 18
    [3] => 17
    [4] => 25
  )

 

 

参考链接:https://blog.csdn.net/jiangnanqbey/article/details/81354968 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM