Jump to content

[SOLVED] Removing a complete text that might contain a certain caracters in it


crawlerbasher

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.