Home > Backend Development > PHP Tutorial > 正则效率太低有没有办法用其它办法代替

正则效率太低有没有办法用其它办法代替

WBOY
Release: 2016-06-23 13:24:23
Original
1328 people have browsed it

要把   ab100bc200cd300 这个字符串格式化为 ab=>100、bc=>200、cd=300,也就是英文+数字
使用正则虽然可以,但是效率性能太低,有没有办法用其它方实现呢?求大神解答


回复讨论(解决方案)

$s = 'ab100bc200cd300';preg_match_all('/([a-z]+)(\d+)/', $s, $m);$t = array_combine($m[1], $m[2]);print_r($t);
Copy after login
Array(    [ab] => 100    [bc] => 200    [cd] => 300)
Copy after login
效率低吗?没看出来

用版主这个方法,效率好像高了。看来代码的优化很重要。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template