Created
January 28, 2014 19:34
-
-
Save mingomax/8674521 to your computer and use it in GitHub Desktop.
Parse para tratar a seguite estrutura de dados @[12334243:Fulando Cilano]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Funcao auxiliar que processa o conteudo e retira os usuarios mencionados no post | |
* @author Domingos Teruel | |
**/ | |
function split_content_mentioneds($content) { | |
$pattern = "/((@\[(\d)+\:)([\w\d\s\_\.(\:){2}]+)\])/"; | |
//Cria os links para os perfis mencionandos | |
$html = preg_replace_callback( | |
$pattern, | |
function($matched){ | |
preg_match("(\b[0-9]+\b)", $matched[2],$user_id); | |
return "<a href=\"profile/{$user_id[0]}\">{$matched[4]}</a>"; | |
}, | |
$content | |
); | |
//gera uma lista dos perfis mencionados | |
preg_match_all("(\b[0-9]+\b)", $content, $users_mentioned); | |
return array( | |
'mentioneds' => $users_mentioned[0], | |
"content" => $html | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment