Remove . (dot) from a string using php

Posted: February 15, 2011 in regex
Tags: , , , ,

Have you ever faced issue with your hosting server when you send html email with some email addresses in it? Replace your string with the following php regular expression.

 

<?php
//Html string you want to replace
$html_message=    “Its sample message with two email address in it. abc@gmail.com and xyz@yahoo.co.in”;

//Cleaned string
$cleaned_message = preg_replace(‘/\b([A-Z0-9._%+-]+@[A-Z0-9.-]+)(\.)([A-Z]{2,4}\b)/i’, ‘$1.$3’, $html_message);

echo $cleaned_message;
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s