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


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.