Return to Snippet

Revision: 32809
at October 2, 2010 09:25 by thefrosty


Initial Code
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');

Initial URL
http://themelit.com/themes/tweets/

Initial Description
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?

Initial Title
preg_replace WordPress content on post_save

Initial Tags
wordpress

Initial Language
PHP