/ Published in: PHP
I\'m definitely not the best at Regex. But this function seems to be timing out, and adding like 4o links to the post. Got any ideas?
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function replaceContent($content = '') { /* Process names */ $content = preg_replace("~@(\w+)~", "<a href=\"http://www.twitter.com/\\1\" class=\"twitter-anywhere-user\">@\\1</a>", $content); $content = preg_replace("~^(\w+):~", "<a href=\"http://www.twitter.com/\\1\" class=\"twitter-anywhere-user\">@\\1</a>:", $content); /* Process hashtags */ $content = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $content); /* Process links */ $content = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" rel=\"external nofollow\">\\2</a>", $content); $content = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" rel=\"external nofollow\">\\2</a>", $content); return $content; } add_action('save_post', 'replaceContent');
URL: http://themelit.com/themes/tweets/