ellandrd
asked on
remove all external links from string
i have a string:
$data = '<p>Click here to <a href="http://www.mysite.com/contact.html" title="Contact us">contact us</a> or <a href="about.html" title="About us">read more about us</a> or click here to <a href="mailto:info@mysite.c om" title="Email us">email us</a> or visit my friends site at <a href="http://www.anothersite.com" title="Friends site">http://www.anothersite.com</a> to speak to contact him.</p>';
Basically what i would like is to do is remove the <a></a> tags from all external links. So my string would look like this:
$data = '<p>Click here to <a href="http://www.mysite.com/contact.html" title="Contact us">contact us</a> or <a href="about.html" title="About us">read more about us</a> or click here to <a href="mailto:info@mysite.c om" title="Email us">email us</a> or visit my friends site at http://www.anothersite.com to speak to contact him.</p>';
Please advise with example snippets.
$data = '<p>Click here to <a href="http://www.mysite.com/contact.html" title="Contact us">contact us</a> or <a href="about.html" title="About us">read more about us</a> or click here to <a href="mailto:info@mysite.c
Basically what i would like is to do is remove the <a></a> tags from all external links. So my string would look like this:
$data = '<p>Click here to <a href="http://www.mysite.com/contact.html" title="Contact us">contact us</a> or <a href="about.html" title="About us">read more about us</a> or click here to <a href="mailto:info@mysite.c
Please advise with example snippets.
ASKER
that removes all links. i only want to remove external links.
i found this previous question where the asker wanted to remove internal links but i cant make it work for only external, keeping internal links
https://www.experts-exchange.com/questions/21985319/Remove-Internal-Hyperlinks.html
Maybe you can??
i found this previous question where the asker wanted to remove internal links but i cant make it work for only external, keeping internal links
https://www.experts-exchange.com/questions/21985319/Remove-Internal-Hyperlinks.html
Maybe you can??
then just change your "badwords" array as appropriate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks.
$swapbad = array(",",":",";","%","htt
$nobadwords = " ** ";
foreach($swapbad as $replace){
$badwords = str_replace($swapbad,$noba
}
return $badwords;
}
just call it like filter($data);
This checks all stuff found in $data against the array and swaps it for **