Guest User

Untitled

a guest
Oct 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. array('pergunta', 'stackoverlow', 'respostas');
  2.  
  3. #notícias
  4. #sãoPaulo
  5.  
  6. <?php
  7.  
  8. $str = '#pergunta no #stackoverlow #notícias 2015 #sãoPaulo';
  9. preg_match_all('/#w+/iu', $str, $itens);
  10.  
  11. echo "<pre>";
  12. print_r($itens);
  13.  
  14. Array
  15. (
  16. [0] => Array
  17. (
  18. [0] => #pergunta
  19. [1] => #stackoverlow
  20. [2] => #notícias
  21. [3] => #sãoPaulo
  22. )
  23.  
  24. )
  25.  
  26. $tweet = "this has a #hashtag a #badhash-tag and a #goodhash_tag";
  27.  
  28. preg_match_all("/(#[^ #]+)/", $tweet, $matches);
  29.  
  30. var_dump( $matches );
  31.  
  32. function extractTags($mensagem)
  33. {
  34. // Casa tags como #dia #feliz #chateado
  35. // Não casa caracteres especias #so-pt
  36. $pattern = '/#(w+)/u';
  37.  
  38. // Alternativa para incluir outros caracteres
  39. // Basta incluir entre os colchetes
  40. //$pattern = '/#([w-]+)/u';
  41.  
  42. preg_match_all($pattern, $mensagem, $tags);
  43.  
  44. // Utiliza o vetor com os grupos capturados entre parenteses
  45. return $tags[1];
  46. }
  47.  
  48. preg_replace('/#[A-Za-z-0-9]+/m',$string,$matches);
  49. var_dump( $matches );
Add Comment
Please, Sign In to add comment