dopcpc9207 2018-01-25 09:35
浏览 121
已采纳

PHP从字符串中获取特定的整数

I want to extract the ID which is the first integer in the string below:

ID:40021223
CSQ(0-31): 31
Online

I only want the to get 40021223

  • 写回答

3条回答 默认 最新

  • douri4459 2018-01-25 09:46
    关注
    $str = 'ID:40021223';   //pass any string
    echo $output = getID($str); 
    
    function getID($str) {
       $res = explode(':',$str);  //split string with :
       if(in_array('ID',$res)) {  //if array contain Id then it will give the exact output else null
          return $res[1];
       } else {
          return null;
       }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?