21,891
社区成员
发帖
与我相关
我的任务
分享
$content = "asdfasdfasdf<a href=><img ></a>asdfasdf";
$content = preg_replace("/<a.*?[^img]<\/a>/i", "", $content);
echo $content;
<?php
$str = "<a href='casd' > scay </a> <a href='casd' > <img />cay </a>\n<a href='casd' > scay </a> <a href='casd' > <img />cay </a>";
$str_s = preg_replace('/<a[^>]+>(?![^<>]+<img).*?<\/a>/im' , '' , $str);
echo htmlspecialchars($str_s);
?><?php
$str = "<a href='casd' > scay </a> <a href='casd' > <img />cay </a>\n<a href='casd' > scay </a> <a href='casd' > <img />cay </a>";
[code=PHP]
$str = "<a href='casd' >cay </a> <a href='casd' ><img />cay </a> ";
function imgcheck($str){
return preg_match("/<img[^>]+?>/",$str[0])?$str[0]:'';
}
echo preg_replace_callback("/(<a[^>]+?>.+?<\/a>)/","imgcheck",$str);
$content = preg_replace("/<a.*?(?!img)<\/a>/i", "", $content);