jorley Posted February 17, 2010 Share Posted February 17, 2010 Hi guys, I have a network that I am working on and people keep posting links to their pesonal sites even though its against the terms. I need to write a function to remove these links. The problem is that sometimes they put in www, sometime http, sometimes spaces of whatever they can to get past it. Removing people that do this is something we are trying to avoid. Lastly, when posting it in someplaces it removes the tags in others it keeps it so the <a isnt always there. I am assuming we are talking regex which I have been using but I cant figure this one out. Can anyone point me in the right direction? I just want to replace them with a few characters to hokd its place but not show it. Link to comment https://forums.phpfreaks.com/topic/192348-removing-links-in-text/ Share on other sites More sharing options...
Catfish Posted February 17, 2010 Share Posted February 17, 2010 preg_replace('/<a.*<\/a>/U', '', $string); // remove: <a(any number of characters)</a> from $string not sure how to remove other urls like: sub.domain.net where sub, domain and net can all be varying. you will need one of the real regexp gurus here to help with that Link to comment https://forums.phpfreaks.com/topic/192348-removing-links-in-text/#findComment-1013633 Share on other sites More sharing options...
satya61229 Posted February 17, 2010 Share Posted February 17, 2010 You should use regex. May be this: preg_replace('@<a(.*)[>](.*)</a>@imU', '', $text); Link to comment https://forums.phpfreaks.com/topic/192348-removing-links-in-text/#findComment-1013669 Share on other sites More sharing options...
jorley Posted February 17, 2010 Author Share Posted February 17, 2010 Thanks Catfish. I tried it out and it removes the link which is what I need. There will always be work arounds but i figure if someone goes through the process of creating a work around then I will remove them from the site because at that point its blatant. Thanks again. Link to comment https://forums.phpfreaks.com/topic/192348-removing-links-in-text/#findComment-1013904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.