‘壹’ php 过滤掉超链接,及超链连内的网页代码
用正则表达式过滤掉所有HTML代码
过滤所有html标签的正则表达式:
</?[^>]+>
‘贰’ php正则表达式去除超链接。
preg_replace正则匹配,去除所有a链接地址,并且保留里面a里面的内容
preg_replace(“#<a[^>]*>(.*?)</a>#is”, “$1”,$body);
ereg_replace正则匹配:
ereg_replace(“]*>|</a>”,””,$content);
ereg_replace函数匹配以”<a “开头,中间除>以外的所有字符,再以>结尾的字符串或匹配””字符。匹配到的字符串赋为空。
‘叁’ php怎么用正则判断文章中是否有超链接
$text="测试内容<a href=\"http://mp3..com\">MP3</a><a href=\"http://image..com\">图片</a>正文<a href=\"http://video..com\">视频</a>";
$text1="测试内容";
preg_match_all("#<a([^>]*)>(.*)<\/a>#iU", $text, $arr);
//print_r($arr);
var_mp($arr);
if( $arr[0] ){
echo "包含超链接";
}else{
echo "恭喜,没有超链接";
}
之前正好回答了另一个朋友同样的问题,以上代码经过测试是OK的。
‘肆’ PHP正则过滤链接地址中的字符
preg_replace('/(<a\b[^>]*)_bmiddle/','$1',$str);
‘伍’ 正则 内容去除超链接 php
正则替换那句改为:
$str = preg_replace('/(<a.*?>\s*)(.*大连.*)(\s*<\/a>)/', '${2}', $str);
‘陆’ php高手请进:正则提取超链接中的网址和标题,如果兼顾有双引号和单引号或没有引号的超链接
<?php
$text = "递归是一种函数调用自身的机制。这是一种强大的特性可以把某些复杂的东西变得很简单。<a href='http://mp3..com'>MP1</a><a href=http://mp3..com>MP2</a><a href='http://mp3..com' target='_blank'>MP3</a><a href=http://mp3..com target=mainFrame>MP4</a><a href=http://mp3..com style=\"font-size:32px;color:#e53333;\">MP5</a><a href=\"http://mp3..com\">MP6</a>";
preg_match_all('/<a href=(.*)>(.*)<\/a>/isU',$text,$data_arr);
foreach( $data_arr[1] as $key=>$val ) {
$replace_str = $data_arr[0][$key];
$title = $data_arr[2][$key];
preg_match("/(https?|ftp|mms):\/\/([A-z0-9]+[_\-]?[A-z0-9]+\.)*[A-z0-9]+\-?[A-z0-9]+\.[A-z]{2,}(\/.*)*\/?/",$val,$url_data);
$url = $url_data[0];
$text = str_replace($replace_str,"<br/>\n{$title} {$url}",$text);
}
var_mp($text);
?>
这个可以识别得了网址中包含http开头的链接地址格式的。但如果还需匹配相对地址,建议是将所有可能出现的情况一一替换掉