字符串如下,我想清除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));
其实你的也很省资源了
试试这个
$vid = "http://ooioosy.wwowo9e.com/owuiwd/vid=198445623";echo explode('vid=', $vid)[1];
<?php$vid = "http://ooioosy.wwowo9e.com/owuiwd/vid=198445623";str_replace('http://ooioosy.wwowo9e.com/owuiwd/vid=','',$vid );?>
<?php$vid = "http://ooioosy.wwowo9e.com/owuiwd/vid=198445623";str_replace('http://ooioosy.wwowo9e.com/owuiwd/vid=','',$vid );?>直接用=分割成数组,取第一个元素不就可以了
我觉得你的已经很省了!
$str = 'http://ooioosy.wwowo9e.com/owuiwd/vid=198445623'; $arr = explode('=',$str); echo $arr[1];
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号