Posted By

rwunsch on 03/17/12


Tagged

regex html links anchor regular Expression href pregreplace anchors


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Terion
danfolt
guillermoj88gmailcom


Remove / Replace - href / anchor /link - in html /string - preg_replace - php - regex - regular expression


 / Published in: PHP
 

Replaces all links within href part of anchor in a HTML-String.

  1. /*
  2.  * DO NOT USE THE PATTERN STRING DIRECTLY IN 'preg_match()' !!!!
  3.  *
  4.  */
  5. $pattern = '/(?<=href\=")[^]]+?(?=")/';
  6. $replacedHrefHtml = preg_replace($pattern, $replacement, $html);

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: rwunsch on March 17, 2012

$pattern = '/(?

You need to login to post a comment.