Jump to content

User content removal


fc123

Recommended Posts

I have used regex to remove links from user submitted content in the following function:

 

function linkremove($text)
{
$text = preg_replace("#www\.(.+?)\.com#is", "", $text);
$text = preg_replace("#www\.(.+?)\.net#is", "", $text);
$text = preg_replace("#www\.(.+?)\.co.uk#is", "", $text);
$text = preg_replace("#www\.(.+?)\.org#is", "", $text);
return $text;
}

 

Although not the most difficult to get around it seems somewhat effective at this moment in time.

 

However, sometimes users also use my BBCode to insert pictures

 

such as:

[ img ] www.p1.examplesite.com/folder/pic.jpg [ / img ] or

[ img ] www.examplesite.com/folder/pic.jpg [ / img ]

 

which when submitted strips out the www.p1.examplesite.com / www.examplesite.com

 

Is there a way I can add a line to my code above that can identify SAFE sites that I specify and ignore or leave these these, such as photobucket so that the image can be shown?

 

I hope I explained that well...

Link to comment
https://forums.phpfreaks.com/topic/97232-user-content-removal/
Share on other sites

<?php
function linkremove($text)
{
  if (!preg_match('#\.(jpe?g|gif|png|bmp)$#is'), $text):
    $text = preg_replace("#www\.(.+?)\.com#is", "", $text);
    $text = preg_replace("#www\.(.+?)\.net#is", "", $text);
    $text = preg_replace("#www\.(.+?)\.co.uk#is", "", $text);
    $text = preg_replace("#www\.(.+?)\.org#is", "", $text);
  endif;
return $text;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/97232-user-content-removal/#findComment-497535
Share on other sites

I'm sorry I realized the above script is totally useless, because you're not testing single links but whole text. You need to use preg_match to capture all links to an array, then loop through it and use the if (!preg_match('#\.(jpe?g|gif|png|bmp)$#is'), $text) condition to identify image links and let them through. I'll write it down if you won't, but right now I'm off to pub ;)

 

 

Link to comment
https://forums.phpfreaks.com/topic/97232-user-content-removal/#findComment-497562
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.