Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array('pergunta', 'stackoverlow', 'respostas');
- #notícias
- #sãoPaulo
- <?php
- $str = '#pergunta no #stackoverlow #notícias 2015 #sãoPaulo';
- preg_match_all('/#w+/iu', $str, $itens);
- echo "<pre>";
- print_r($itens);
- Array
- (
- [0] => Array
- (
- [0] => #pergunta
- [1] => #stackoverlow
- [2] => #notícias
- [3] => #sãoPaulo
- )
- )
- $tweet = "this has a #hashtag a #badhash-tag and a #goodhash_tag";
- preg_match_all("/(#[^ #]+)/", $tweet, $matches);
- var_dump( $matches );
- function extractTags($mensagem)
- {
- // Casa tags como #dia #feliz #chateado
- // Não casa caracteres especias #so-pt
- $pattern = '/#(w+)/u';
- // Alternativa para incluir outros caracteres
- // Basta incluir entre os colchetes
- //$pattern = '/#([w-]+)/u';
- preg_match_all($pattern, $mensagem, $tags);
- // Utiliza o vetor com os grupos capturados entre parenteses
- return $tags[1];
- }
- preg_replace('/#[A-Za-z-0-9]+/m',$string,$matches);
- var_dump( $matches );
Add Comment
Please, Sign In to add comment