Skip to content

Instantly share code, notes, and snippets.

@stephanebruckert
Created December 23, 2014 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephanebruckert/93c066c45afbdbc64bfd to your computer and use it in GitHub Desktop.
Save stephanebruckert/93c066c45afbdbc64bfd to your computer and use it in GitHub Desktop.
Handle Facebook Graph Markup http://stackoverflow.com/q/27347844/1515819
function get_html_description($description) {
return
// 1. Handle tags (pages, people, etc.)
preg_replace_callback("/@\[([0-9]*):([0-9]*):(.*?)\]/", function($match) {
return '<a href="http://facebook.com/'.$match[1].'">'.$match[3].'</a>';
},
// 2. Handle hashtags
preg_replace_callback("/#(\w+)/", function($match) {
return '<a href="http://facebook.com/hashtag/'.$match[1].'">'.$match[0].'</a>';
},
// 3. Handle breaklines
str_replace("\n", "<br />", $description)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment