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.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment