Seamless Posted March 6, 2006 Share Posted March 6, 2006 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})$Anywaya solution or advice would be musch appreciated.ThanksSeamless Quote Link to comment Share on other sites More sharing options...
Guest edwinsweep Posted March 6, 2006 Share Posted March 6, 2006 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 Link to comment Share on other sites More sharing options...
Seamless Posted March 6, 2006 Author Share Posted March 6, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
zq29 Posted March 6, 2006 Share Posted March 6, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
Seamless Posted March 6, 2006 Author Share Posted March 6, 2006 [!--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 postfunction 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. Quote Link to comment Share on other sites More sharing options...
Seamless Posted March 6, 2006 Author Share Posted March 6, 2006 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.SeamlessSOLVED Quote Link to comment 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.