Skip to content

Instantly share code, notes, and snippets.

@mingomax
Created January 28, 2014 19:34
Show Gist options
  • Save mingomax/8674521 to your computer and use it in GitHub Desktop.
Save mingomax/8674521 to your computer and use it in GitHub Desktop.
Parse para tratar a seguite estrutura de dados @[12334243:Fulando Cilano]
<?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