-1
I have this function below:
function filterEmail($text)
{
return preg_replace('/(.*)[a-z0-9\.\_\-]+@[a-z0-9\.\_\-]+\.[a-z]+(.*)/i','', $text);
}
It removes lines who have email.
I have a textarea
, and sometimes users post the email, so whenever it puts the email, this function removes.
Ex: Hello guys, all right?
I really liked the site.
Send me an e-mail [email protected]
With this function, the content is like this:
Ex:
Hello guys, all right?
I really liked the site.
So far so good. What I need is the same function, but also remove URL. If possible using the preg_replace
.
And finally, sometimes users put three line breaks (\n\n)
- I need that whenever you put three line breaks (or more), it leaves only two. But only when there are three line breaks or more..
Ex:
Hello guys, all right?
I really liked the site.
Should stay:
Hello guys, all right?
I really liked the site.
Someone?????????
– Luhhh
A hint, instead of using the deletion of the entire line with preg_replace, could delete only the email, as the user can type other things in the line along with the email I use :
preg_replace('/([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/','', $text);
– Gabriel Garcia