Jump to content

Strip Links From Description


CMoore

Recommended Posts

One of the issues that we face on or Senioridy.com site is that users will often posts links that open in the parent window within their descriptive text, which places the site visitor onto the linked site instead of ours. Since we already have custom fields that users can utilize in order to post specific links that we allow, we don't really prefer to allow them to post links within the body of the descriptive text.

So, in order to remove any links placed within the description we use a bit of regex to remove the links, but keep the text:

 

<?php 
$descr = $listing['Listing']['text'] !== strip_tags($listing['Listing']['text']) ? $listing['Listing']['text'] : nl2br($listing['Listing']['text']);
 
echo preg_replace('#<a.*?>(.*?)</a>#i', '\1', $descr);
?>
 
I thought I'd share this with the community in case there was a need for it.
Link to comment
  • 2 months later...
  • 5 weeks later...
×
×
  • Create New...