字符串如下,我想清除vid=及之前的字符,也就是只保留198445623。这其中只有vid=是固定的字符。
http://ooioosy.wwowo9e.com/owuiwd/vid=198445623我现在的方法是这样的,通过计算vid=的位置来清除,有没有更节省系统资源的方法?
$vid = "http://ooioosy.wwowo9e.com/owuiwd/vid=198445623"
substr($vid,(stripos($vid,'vid=')+4));

解决方案 »

  1.   

    其实你的也很省资源了
    试试这个
    $vid = "http://ooioosy.wwowo9e.com/owuiwd/vid=198445623";
    echo explode('vid=', $vid)[1];
      

  2.   

    <?php
    $vid = "http://ooioosy.wwowo9e.com/owuiwd/vid=198445623";
    str_replace('http://ooioosy.wwowo9e.com/owuiwd/vid=','',$vid );
    ?>本来想用正则,不过正则浪费资源
      

  3.   

    LZ写得很明白——“这其中只有vid=是固定的字符”
      

  4.   

    $str = 'http://ooioosy.wwowo9e.com/owuiwd/vid=198445623';
    $arr = explode('=',$str);
    echo $arr[1];