php正则提取字符串内容,并循环输出值。

<?php
$str = '<a href=\'javascript:Chapter("2.html","1.html");\' >title</a>';
$output = array();
if (preg_match_all('~javascript:Chapter\("([^"]+)","([^"]+)"\)[^>]+>([^<]+)</a>~is', $str, $chapter)) {
    foreach ($chapter[1] as $k => $c) {
        $tmp[] = $c . "-" . $chapter[2][$k] . "-" . $chapter[3][$k];
    }
    sort($tmp);
    print_r($tmp);
}

转载请注明出处 智博小宇 » php正则提取字符串内容,并循环输出值。