Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.