Find matching HTML tags (greedy)

Google AD

参考:http://cn.php.net/preg_match_all 非常有用的正则。
<?php
// The \\2 is an example of backreferencing. This tells pcre that
// it must match the second set of parentheses in the regular expression
// itself, which would be the ([\w]+) in this case. The extra backslash is
// required because the string is in double quotes.
$html = “<b>bold text</b><a href=howdy.html>click me</a>”; preg_match_all(“/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/”, $html, $matches, PREG_SET_ORDER);foreach (

$matches as $val) {
echo
“matched: ” . $val[0] . “\n”;
echo
“part 1: ” . $val[1] . “\n”;
echo
“part 2: ” . $val[3] . “\n”;
echo
“part 3: ” . $val[4] . “\n\n”;
}
?>

相关文章

  1. JQUERY搜索框提示效果
  2. WordPress3.0 的自定义菜单功能
  3. Thinkphp 分页时查询条件保存
  4. HTML Mailto 用法
  5. PHP常用函数

关于站长

姚迎迎,生于 1985年3月2日, 江苏大丰人士 。修行于福州大学软件学院

Taobao AD

Google 广告