preg_replace - url and line break

-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 own e-mail.

I have a textarea , and sometimes the users put the email, so whenever they put the email, this function removes.

Ex: Hello everyone, how are you?

I really liked the site.

Send me an email [email protected]

With this function, the content looks like this:

Ex: Hello, guys, how are you? I really liked the site.

So far so good. What I need is the same function, but also remove URL. If possible using preg_replace .

And finally, sometimes users put three breaks of lines (\n\n) - I need every time I put three breaks of lines (or more), it only leaves two. But only when there are three line breaks or more ..

Ex:

Hello everyone, how are you? Home | I really liked the site.

Should be:

Hello everyone, how are you? Home I really liked the site.

    
asked by anonymous 31.03.2016 / 10:48

1 answer

1

Try the following:

<?php
function filterEmail($texto) {

$texto = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $texto);
$texto = preg_replace('/(.*)[a-z0-9\.\_\-]+@[a-z0-9\.\_\-]+\.[a-z]+(.*)/i','', $texto);
$texto = preg_replace('/[\n\r]{3,}/',"\n\n",$texto);
return $texto;

}

$string = "Olá pessoal, tudo bem?

Gostei muito do site.

Me envie um e-mail [email protected]
http://www.codigosnaweb.com";
echo filterEmail($string);
?>
    
31.03.2016 / 17:33