Created
December 23, 2014 09:29
-
-
Save stephanebruckert/93c066c45afbdbc64bfd to your computer and use it in GitHub Desktop.
Handle Facebook Graph Markup http://stackoverflow.com/q/27347844/1515819
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
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