Page 1 of 1

remove links

Posted: Tue Feb 15, 2011 4:01 pm
by pedroz

Code: Select all

 $string='
<a href="#anchor">0</a>
<a href="http://www.DOMAINa.com" target="_blank">0</a>
<a href="http://www.DOMAINa.com" target="_blank">1</a>
<a title="b" href="http://DOMAINa.com" target="_blank">2</a>
<a title="c" href="http://DOMAINa.com/test#a">3</a>
<a href="http://www.DOMAINb.com" target="_blank">4</a>
<a href="http://www.DOMAINb.com/#domainb">5</a>
';


$pattern = '#<a[^>]+\#[^>]+>(.*?)</a>#i';
$output = preg_replace($pattern, '\\1', $string);  

$pattern = '#<a[^>]+DOMAINa[^>]+>(.*?)</a>#i';
$output = preg_replace($pattern, '\\1', $string);   


// should echo
// 0
// 1
// 2
// 3
// <a href="http://www.DOMAINb.com" target="_blank">4</a>
// <a href="http://www.DOMAINb.com/#domainb">5</a>  

It is not working. Also removing link 5 and want to keep it...
Can you please help?

Re: remove links

Posted: Wed Feb 16, 2011 10:25 am
by ridgerunner
I ran your script and it produced the exact same output you said you wanted.

You have not provided enough information for me to help you.