Skip to content

Instantly share code, notes, and snippets.

@Thalesrup
Created September 6, 2019 18:42
Show Gist options
  • Select an option

  • Save Thalesrup/a7456ca109c67382be7dd9c00aef8cb6 to your computer and use it in GitHub Desktop.

Select an option

Save Thalesrup/a7456ca109c67382be7dd9c00aef8cb6 to your computer and use it in GitHub Desktop.

Revisions

  1. Thalesrup created this gist Sep 6, 2019.
    17 changes: 17 additions & 0 deletions ThalesRuppenthal
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    Expressões regulares podem ser usadas para validação de dados, no caso usei palavras declaradas para realizar determinada ação usando uma function de callback como retorno.

    <?php
    $input = 'and where in select from';
    function verifica($valor)
    {
    $regex = array('/where/','/from/');
    $regular = preg_replace_callback($regex, create_function('$matches', 'return mb_strtoupper($matches[0]);'), $valor);
    echo $regular;
    }
    echo verifica($input);
    echo '<br>';
    ?>

    dica de ide online php para teste do code http://www.writephponline.com/

    Obs: utilizei uma array para conter todas as palavras declaradas que irei utilizar para realizar a determinada ação com callback de uma function