Jump to content

Get value that has... unless...


The Little Guy

Recommended Posts

I don't know of a way to do this *during* a regex, but you could simply iterate over your matches later and filter out those that include javascript.

foreach($arr as $key => $element){
  if(preg_match("#javascript#", $element)){
    unset($arr[$key]);
  }
}

 

I'd love to know if this is possible during a capture.

 

EDIT: actually, my regex above won't do because a url could contain javascript as a url to a page. You would have to amend to include : - and, from what I can tell, your regex will not match against urls which use ' to enclose the href.

Firstly, parsing HTML documents with regex is a really hacky way of doing things. There are tools dedicated to making sense out of (HT|X)ML documents built in to PHP, like DOM.

 

Secondly, you can use a "negative lookahead" within your regular expression to assert that javascript: doesn't appear where you don't want it:

 

~<a.+(href="(?!javascript:)(.+?)")~i

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.