crawlerbasher Posted September 26, 2009 Share Posted September 26, 2009 Ok I've been having a bit of problem with ppl trying to send spam via the send me an email section on the site, desite that html and BB codes are not aloud in the message feild. But with the use of php is it possible to remove a row of text like http://www.spam.com www.spam.com etc.. by checking to see if the text has any http:// or www or .com etc... And if this is in deed possible dose anyone know of any good easy to understand tutorials out there that could help me on my way to improving my contact me section? Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/ Share on other sites More sharing options...
.josh Posted September 27, 2009 Share Posted September 27, 2009 stripos Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-925632 Share on other sites More sharing options...
redarrow Posted September 27, 2009 Share Posted September 27, 2009 my way with example. <?php // url links in a array the only one we want is google.com. $links=array("http://www.google.com","google.com","www.google.com"); //loop throw the array with foreach foreach($links as $wanted_data){ //Use preg_match to get the desired info you want. // /<< start ^ at the begining letters [a-z] and a dot. //letters[a-z] but only there charecters long. if(preg_match("/^[a-z].[a-z]{3}/",$wanted_data)){ //echo the result if there. echo $wanted_data; }else{}; // wast off code but added encase needed. } ?> learn regex. http://www.regular-expressions.info/tutorial.html the only safe way to validate user input properly. Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-925636 Share on other sites More sharing options...
crawlerbasher Posted September 28, 2009 Author Share Posted September 28, 2009 looking at that code, it looks like it would strip everything that did not cotain a link to google. and when testing it it seems to only output google.com I'm still looking at the links given to me, and its very confusing. Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-926591 Share on other sites More sharing options...
TeNDoLLA Posted September 28, 2009 Share Posted September 28, 2009 Could you be more precise what you want to get removed? This would strip links containin www and http beginning. <?php $str = 'Some text diipaapa dasdadad.. www.spam.com some more text lalallaa http://www.haxors.com/ ... text lalala..'; // Strip links from contents. $str = preg_replace('/www[.][^\s][a-z_-].*|http:\/\/www[.][^\s][a-z_-].*/', '', $str); echo $str; Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-926592 Share on other sites More sharing options...
crawlerbasher Posted September 28, 2009 Author Share Posted September 28, 2009 ok say some one sent me an email using the email form and the $comment verable cotained, say this: Hello please check out my site http://www.spamsite.com www.spamsite.com spamsite.com In this instence I would like it to be remove the following http://www.spamsite.com www.spamsite.com spamsite.com so that the output would read Hello please check out my site or even better if it containted any site in any part of the comment it would return an error on the line of I told you no url was permited in this email, go back and try again. Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-926599 Share on other sites More sharing options...
crawlerbasher Posted September 28, 2009 Author Share Posted September 28, 2009 Could you be more precise what you want to get removed? This would strip links containin www and http beginning. <?php $str = 'Some text diipaapa dasdadad.. www.spam.com some more text lalallaa http://www.haxors.com/ ... text lalala..'; // Strip links from contents. $str = preg_replace('/www[.][^\s][a-z_-].*|http:\/\/www[.][^\s][a-z_-].*/', '', $str); echo $str; Thank you this code seems to work well I will look in to the preg_replace code a bit more on how it works. Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-926603 Share on other sites More sharing options...
TeNDoLLA Posted September 28, 2009 Share Posted September 28, 2009 Here is update: <?php $str = 'TEST spamsite.com TEST www.spam.com TEST http://www.haxors.com/ TEST spamsite.com TEST'; // Strip links from contents. $str = preg_replace('/(www[.]|http:\/\/|http:\/\/www[.])[a-z_-].[^\s]*|([a-z_-]+[.](com|org|net)[^\s]*)/i', '', $str); echo $str; but i didnt do any hard testing on it... so it i don't quarantee it will work as supposed in every possible situation. Now it will remove also spamsite.com or anysite.org etc. anywhere in the text. You can also add the site extensions to the part (com|org|net) separated by "|". Also added the i -modifier so it will be case insensitive. But the problem is now if there is words like ASP.net for example those will get removed also. Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-926607 Share on other sites More sharing options...
crawlerbasher Posted September 28, 2009 Author Share Posted September 28, 2009 When I first started to use a send mail script on my site I use to get ppl trying to create a html code, which is not good if some one is trying to do somthing nasty, and getting spam. I used a strptag to remove anything that can be used to try and creat a html script or any other kind, but still was having problem with ppl just sending spam. This will help keep my contact page for ppl that want to contact me and not spam. I'm also going to be working on a script so you have to type the word in the picture before you can send it. I've done that before, its just a matter of rembering how I did it and if I can find the old code, looking at that. Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-926613 Share on other sites More sharing options...
TeNDoLLA Posted September 28, 2009 Share Posted September 28, 2009 If it's very old I suggest you do some investigating on google searching some newer examples. The thing you are looking for is called captcha. I dont know the old code you had but some spambots have improved in going around some captchas also. Quote Link to comment https://forums.phpfreaks.com/topic/175656-solved-removing-a-complete-text-that-might-contain-a-certain-caracters-in-it/#findComment-926691 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.