Jump to content

Removing an email address from body


Seamless

Recommended Posts

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
Link to comment
Share on other sites

Guest edwinsweep
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.
[code]
mysql_query = "SELECT * FROM messages WHERE..."
[/code]
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.
[code]
mysql_query = "SELECT msgname,msgtitle,msgsender FROM messages WHERE..."
[/code]
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).


Link to comment
Share on other sites

[!--quoteo(post=352044:date=Mar 6 2006, 07:13 AM:name=edwinsweep)--][div class=\'quotetop\']QUOTE(edwinsweep @ Mar 6 2006, 07:13 AM) [snapback]352044[/snapback][/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.
[code]
mysql_query = "SELECT * FROM messages WHERE..."
[/code]
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.
[code]
mysql_query = "SELECT msgname,msgtitle,msgsender FROM messages WHERE..."
[/code]
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.
Link to comment
Share on other sites

[!--quoteo(post=352039:date=Mar 6 2006, 11:58 AM:name=Seamless)--][div class=\'quotetop\']QUOTE(Seamless @ Mar 6 2006, 11:58 AM) [snapback]352039[/snapback][/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.
Link to comment
Share on other sites

[!--quoteo(post=352058:date=Mar 6 2006, 08:11 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ Mar 6 2006, 08:11 AM) [snapback]352058[/snapback][/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:
[code]
// 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;
}
[/code]
The only trouble is instead of replacing an email address in the post with '****' it is removing the whole post.

Link to comment
Share on other sites

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

[code]
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;
    }
[/code]

this will now remove an email address from a post.

its use -

[code]
// $_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!

[/code]

Anyway thanks for your help those you contributed.

Seamless

SOLVED
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.