Delete Line with email

Asked

Viewed 35 times

-4

There is a form in PHP, that companies use to post vacancies.

Sometimes they put inside the textarea something like:

Send vacancy to [email protected]

I would like to VIA PHP, delete all lines (only the line, in full) that contained an email. Follow the example below:

Vacancy for Mason

Salario: XXX

City: XXXX

Send e-mail with resume to [email protected]

Task: XXXXXXXXXXXXXXXXXX

You should stay:

Vacancy for Mason

Salario: XXX

City: XXXX

Task: XXXXXXXXXXXXXXXXXX

Remembering that it will not always be Send resume to [email protected]. Sometimes they write differently, such as sending data to, send an email with if data. At last.

  • That’s not a placeholder ?

  • Who? Where is this form from? If it’s not yours, why do you think you’ll be able to change it in PHP (since the form will already be in the browser after the query)? Do you know the name of the object with the textarea? If so, why not just erase its content completely? See how many questions. Sign that your question is not really clear. Please edit it to improve the explanation. :)

3 answers

1

Explode the text area on different lines.
Traverse the resulting array by printing only lines that have no email

$linhas = explode("\n", $textarea);
foreach ($linhas as $linha) {
    // teste básico para presença de email
    if (!preg_match('/[a-z0-9]+@[-a-z0-0]+\.[a-z]+/', $linha)) {
        echo $linha;
    }
}
  • Thanks. How would the preg_match for http and phone?

  • 2

    For http: preg_match('/https?:\/\//', $linha); for telephone (or better, for 9 digits in a row): preg_match('/[0-9]{9}/'), if you want to recognize numbers with spaces or strokes it will be necessary to complicate the regular Expression.

1

The question is very poorly formulated, so you received so many negatives, I hope you edit it so that people will come back to you positive. But from what I understand, you want to filter the email from the textarea field, to do this, there are two ways, you can block email typing using javascript:

<script>
    function removerEmail(input)
    {
       input.value = input.value.replace(/(.*)[a-z0-9\.\_\-]+@[a-z0-9\.\_\-]+\.[a-z]+(.*)/gi,'');
    }
</script>

Html:

<textarea onkeyup="removerEmail(this)" onkeypress="removerEmail(this)">
</textarea>

Take this example.

And in PHP using a filter for the line that contains the email:

function filterEmail($text)
{
   return preg_replace('/(.*)[a-z0-9\.\_\-]+@[a-z0-9\.\_\-]+\.[a-z]+(.*)/i','', $text);
}

0

I’m not sure where to use it, but when I need to inhibit the user from writing, posting, sending or whatever with his email, I use a preg_replace with specifications like the one below. and then the typed email is replaced by [The E-MAIL CANNOT BE DISPLAYED]

$text = 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})(\]?)/','[O E-MAIL NAO PODE SER EXIBIDO]', $text);
  • In case it does not delete the line, because sometimes beyond just the email, it may have put some other important information on the line!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.