fork download
  1. <?php
  2.  
  3. $str="Apelido:
  4.  
  5.  
  6. Fulano de Tal";
  7.  
  8. //retira os termos indesejados
  9. $patterns = array();
  10. $patterns[0] = '/Apelido/';
  11. $patterns[1] = '/:/';
  12. $replacements = array();
  13. $replacements[1] = '';
  14. $replacements[0] = '';
  15. $str = preg_replace($patterns, $replacements, $str);
  16.  
  17. $str = preg_replace(array('/\s{2,}/', '/[\n\r\t]/',), array(" ", " "), $str);
  18.  
  19. $str = trim($str);
  20.  
  21. echo $str;
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
Fulano de Tal