php - Removing urls with preg_replace -


i want remove hyperlinks in php

here html

<a rel="nofollow" href="http://www.clickansave.net/download/somethingelse" title="download now" target="_blank"><img src="http://banners.coolmirage.com/download_bt3.png" border="0" alt="download"></a> 

i want remove shown above if clickansave.net found in href.i need solution use preg_replace , not dom following reason :

i know exact structure of html deleted , there 1 occurrence on page. dom overkill in case

i tried following

first started removing

$input = preg_replace('#<img src="http://banners.coolmirage.com/download_bt3.png" border="0" alt="download"><\/a>#s', '' , $input,1); 

from there thought of regex of course not not working

$input = preg_replace('#<a.*?<img src="http://banners.coolmirage.com/download_bt3.png" border="0" alt="download"><\/a>#s', '' , $input,1); 

what this?

$string = 'this string <a rel="nofollow" href="http://www.clickansave.net/download/somethingelse" title="download now" target="_blank"><img src="http://banners.coolmirage.com/download_bt3.png" border="0" alt="download"></a> of text.  there <a href="http://www.google.com">lots of links</a> find , replace.';  $string = preg_replace('~<a.*?</a>~i', 'no_link_here', $string);  print $string; 

this output following:

this string no_link_here of text. there no_link_here find , replace. 

edit:

sorry, hadn't noticed requirement replace clickansave.net urls. use preg_replace instead that.

$string = preg_replace('~<a.*?clickansave\.net.*?</a>~i', 'no_link_here', $string);  print $string; 

that give output:

this string no_link_here of text.  there <a href="http://www.google.com">lots of links</a> find , replace. 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -