Jump to content


Photo

Removing an email address from body


  • Please log in to reply
5 replies to this topic

#1 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 March 2006 - 11:58 AM

Hi,

I'm wondering if anyone can help me?

I am writing a page in php which will allow users to post a message for all to see.

If a user enters their email address in the post i want my script to either delete or replace the email address from in the post.

Any ideas?

i've been looking along the lines of str_replace() is this right?

i also have a the format of an email which i can implement but i'm just not sure how

^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$

Anyway

a solution or advice would be musch appreciated.

Thanks

Seamless

#2 Guest_edwinsweep_*

Guest_edwinsweep_*
  • Guests

Posted 06 March 2006 - 12:13 PM

i would suggest just not to ask the database to send the email addres.
if you are using a database and the messages the people post are stored in that database, the messages will have to be extracted from the database to be shown as a page.
here is a mysql example.
mysql_query = "SELECT * FROM messages WHERE..."
this above will select every entry from the message you selected with the WHERE command.
instead of doing this just SELECT only the needed entry's and display them on the screen.
just leave out email addres, like this.
mysql_query = "SELECT msgname,msgtitle,msgsender FROM messages WHERE..."
if you want the users to be able to send an email message to the poster you could design a mail form that will never show his email address.(just a theorie).




#3 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 March 2006 - 12:55 PM

[!--quoteo(post=352044:date=Mar 6 2006, 07:13 AM:name=edwinsweep)--][div class=\'quotetop\']QUOTE(edwinsweep @ Mar 6 2006, 07:13 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
i would suggest just not to ask the database to send the email addres.
if you are using a database and the messages the people post are stored in that database, the messages will have to be extracted from the database to be shown as a page.
here is a mysql example.
mysql_query = "SELECT * FROM messages WHERE..."
this above will select every entry from the message you selected with the WHERE command.
instead of doing this just SELECT only the needed entry's and display them on the screen.
just leave out email addres, like this.
mysql_query = "SELECT msgname,msgtitle,msgsender FROM messages WHERE..."
if you want the users to be able to send an email message to the poster you could design a mail form that will never show his email address.(just a theorie).
[/quote]

Cheers for the reply however, i think either you have misunderstood my post or my explanation wasn't very good,

this is not a mysql problem, the post or message is being inserted into the database correctly. BUT if a user decides to enter their email address into the post i want to take the email address out so when i collect the information from the database to display it, it displays their post without the email address.

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 06 March 2006 - 01:11 PM

[!--quoteo(post=352039:date=Mar 6 2006, 11:58 AM:name=Seamless)--][div class=\'quotetop\']QUOTE(Seamless @ Mar 6 2006, 11:58 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]i also have a the format of an email which i can implement but i'm just not sure how

^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$[/quote]
What you have there is a regular expression, this can be used with the function preg_replace() - Check the details in the manual, this function should help you with what you are trying to do.

#5 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 March 2006 - 01:19 PM

[!--quoteo(post=352058:date=Mar 6 2006, 08:11 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 6 2006, 08:11 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What you have there is a regular expression, this can be used with the function preg_replace() - Check the details in the manual, this function should help you with what you are trying to do.
[/quote]

Ok, after a little research i have got a little function:
// input post
function extract_emails_from($string){
// check if an email is present
        $email = preg_match("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string);
// value you replace email address with
        $new_email = "*****";
// replaces email with new value in post
      $new_string = str_replace($email, $new_email, $string);
// returns post without email
    return $newstring;
}
The only trouble is instead of replacing an email address in the post with '****' it is removing the whole post.



#6 Seamless

Seamless
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 06 March 2006 - 02:40 PM

After palying around with the function from my previous post i came up with this:

function remove_emails_from($string){
        $pattern = "/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i";
        $new_email = " ";
        $new_string = preg_replace($pattern, $new_email, $string);
    return $new_string;
    }

this will now remove an email address from a post.

its use -

// $_POST[post_body] = "My email is someone@example.com email me!";

$post_body = remove_emails_from($_POST[post_body]);

// Output would be - My email is  email me!


Anyway thanks for your help those you contributed.

Seamless

SOLVED




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users