Home >Backend Development >PHP Tutorial >External link code function in php regular string_PHP tutorial

External link code function in php regular string_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:07:54966browse

php教程 正则字符串中外部链接代码函数

function deleteemptyarray( $val )
{
 $links ='';
 if( is_array( $val ) )
 {
  foreach( $val as $v =>$_v)
  {
   if( !empty( $_v[0] ) )
   {
    $links .=$_v[0].'|';
   }
  }  
  return substr($links,0,-1);
 }
 else
 {
  return false;
 }
}

function getoutlink($body)
{
 
 $tempcontent = $body;
 preg_match_all("//i",$tempcontent,$tempurl);
 $urls =array();
 foreach($tempurl[0] as $value)
 {
  if(strstr($value,'http') )
  {
   if(stristr($value ,$localurl))
   {
    continue;
   }
   else
   {    
    preg_match_all("/hrefs*=s*(['"]?)(.*?)1/is", $value, $vlink);    
    $urls[] = $vlink[2];
   }
  }
 }
 //print_r($urls);
 $strurl = explode('|',deleteemptyarray( $urls));
 $tempcount = array_unique($strurl);
 echo ' 外链'.count($tempcount)-1;
}

//调用方法

$body ="aaa我是外部连接";
echo getoutlink($body);

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444911.htmlTechArticlephp教程 正则字符串中外部链接代码函数 function deleteemptyarray( $val ) { $links =''; if( is_array( $val ) ) { foreach( $val as $v =$_v) { if( !empty( $_v[0] ) ) { $...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn