• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Regular Expression

Hmm
I am trying to do an expression and use preg_replace to remove all urls, except some
ie

/<a(.*?)href=\"(.*?)(ebay.\.com)(.*?)\"(.*?)<\/a>/

Where that would remove all urls except ebay.
but it dosn't replace anything, how can I tell it to 'ignore' ebay.com?
0
wildzero
Asked:
wildzero
1 Solution
 
steelseth12Commented:
try this

function check_url($matches){
 
 
  $url = "";
 
  $array_ignore = array("ebay.com","google.com"); // will ignore ebay.com and google.com ---- add urls here
 
 $prepare_url = parse_url($matches[1]);
 
 if($prepare_url["host"]) {
 
       $url = str_replace("www.","",strtolower($prepare_url["host"]));
 
 }else{
 
       return false;
 }
 
  if(in_array($url,$array_ignore)) {
 
        return $matches[0];
 
  }else{
 
        return false;
 
  }
}


echo preg_replace_callback('@<a href="([^"]+)">[^<]+</a>@',"check_url",$string);
0
 
wildzeroAuthor Commented:
Great!
Thats working perfect
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now