一般的捕获组可以用 \0 \1 \N 来表名,如果是用 P<xxx> 这样命名的捕获结果, 在替换参数中用什么来表示 ?
<?php
$text="<span style='some' > AAAA </span>";
$text.="<img style='some' />";
$text.="<p style='some' >";
$text.="<img style='some' />";
$text.="<p style='some' > some </p>";
$out=preg_replace("/<(?P<TAG>span|p)[^>]+>(.+)<\/(\k<TAG>)>/","[\P=
TAG]\\1[\/\k<TAG>]",$text);
print_r( $out);
好象直接用k<xxx> 这样不行
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
http://php.net/manual/en/function.preg-replace.php