又来问正则了。。麻烦各位! 这样一类的地址abc/def/ghi/123456.shtmlabc/def/123456.shtmlabc/123456.shtml只取出中间的数字,其它的不要,请问怎么写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 define('PATTERN', '/(?P<path>(\w+\/)(?2)*)(?P<number>\d+)\.(?P<suffix>\w+)/');$array = array( 'abc/def/ghi/123456.shtml', 'abc/def/ghi/123456.shtml', 'abc/123456.shtml' ); foreach($array as $string) { preg_match_all(PATTERN, $string, $matches_all, PREG_SET_ORDER); echo "----------------------match string: $string.-----------------------------\n"; foreach($matches_all as $matches) { echo "path: ${matches['path']}, number: ${matches['number']}, suffix: ${matches['suffix']}.\n"; } echo "\n";}/**输出如下: ----------------------match string: abc/def/ghi/123456.shtml.-----------------------------path: abc/def/ghi/, number: 123456, suffix: shtml.----------------------match string: abc/def/ghi/123456.shtml.-----------------------------path: abc/def/ghi/, number: 123456, suffix: shtml.----------------------match string: abc/123456.shtml.-----------------------------path: abc/, number: 123456, suffix: shtml. */ $str= <<<HTMLabc/def/ghi/123456.shtmlabc/def/123456.shtmlabc/123456.shtmlHTML;preg_match_all('/(\d+)/s',$str,$matches);print_r($matches[1]);Array( [0] => 123456 [1] => 123456 [2] => 123456) PHP 怎么取得当前操作的纪录ID???? 求救!!! php可以连上mysq但不能选择数据库???l 有关google蜘蛛搜索乱码问题 PHP数组怎样显示在前台页面 排序然后写入数据库,在线等 以最高分回报:两个时间相减,怎样才能得到相差的分钟数? 请各位敬爱的高手帮一下忙! 关于PHP与SQL问题! 有没有截取google搜索结果的代码? 请教关于mysql中的字段值在页面上的输出的问题 求助!使用php本地缓存微信access_token,提示没有写入权限!!! 上传表单到服务器,但服务器不能获取上传文件的数据 js图片向上不间断滚动代码复制到php中,为什么滚动一次就会停止
define('PATTERN', '/(?P<path>(\w+\/)(?2)*)(?P<number>\d+)\.(?P<suffix>\w+)/');
$array = array(
'abc/def/ghi/123456.shtml',
'abc/def/ghi/123456.shtml',
'abc/123456.shtml'
);
foreach($array as $string) {
preg_match_all(PATTERN, $string, $matches_all, PREG_SET_ORDER);
echo "----------------------match string: $string.-----------------------------\n";
foreach($matches_all as $matches) {
echo "path: ${matches['path']}, number: ${matches['number']}, suffix: ${matches['suffix']}.\n";
}
echo "\n";
}/**
输出如下:
----------------------match string: abc/def/ghi/123456.shtml.-----------------------------
path: abc/def/ghi/, number: 123456, suffix: shtml.----------------------match string: abc/def/ghi/123456.shtml.-----------------------------
path: abc/def/ghi/, number: 123456, suffix: shtml.----------------------match string: abc/123456.shtml.-----------------------------
path: abc/, number: 123456, suffix: shtml. */
$str= <<<HTML
abc/def/ghi/123456.shtml
abc/def/123456.shtml
abc/123456.shtml
HTML;
preg_match_all('/(\d+)/s',$str,$matches);
print_r($matches[1]);Array
(
[0] => 123456
[1] => 123456
[2] => 123456
)