到目前为止,我通过这样做成功地分离并计算了字符串中的图片:
preg_match_all('#<img([^<]+)>#', $string, $temp_img);
$count=count($temp_img[1]);我想用类似的部件做一些类似的事情,如下所示:
"code=mYrAnd0mc0dE123“。
例如,假设我有这样的字符串:
$string="my first code is code=aZeRtY and my second one is code=qSdF1E"我想将"aZeRtY“和"qSdF1E”存储在一个数组中。
我尝试了一堆正则表达式来分离"code=...“但没有一个对我有效。显然,正则表达式超出了我的能力范围。
发布于 2013-07-11 22:52:37
你在找这个吗?
preg_match_all('#code=([A-Za-z0-9]+)#', $string, $results);
$count = count($results[1]);发布于 2013-07-11 23:01:38
这一点:
$string = '
code=jhb2345jhbv2345ljhb2435
code=jhb2345jhbv2345ljhb2435
code=jhb2345jhbv2345ljhb2435
code=jhb2345jhbv2345ljhb2435
';
preg_match_all('/(?<=code=)[a-zA-Z0-9]+/', $string, $matches);
echo('<pre>');
print_r($matches);
echo('</pre>');输出:
Array
(
[0] => Array
(
[0] => jhb2345jhbv2345ljhb2435
[1] => jhb2345jhbv2345ljhb2435
[2] => jhb2345jhbv2345ljhb2435
[3] => jhb2345jhbv2345ljhb2435
)
)但是,如果没有后缀分隔符,如果将此模式连接在一起,它将无法正常工作,例如:code=jhb2345jhbv2345ljhb2435code=jhb2345jhbv2345ljhb2435
但也许这对你来说不是问题。
https://stackoverflow.com/questions/17596511
复制相似问题