[wp-hackers] Howto exclude capital words (within URL address) from being searched and replaced?

Chetan Kunte ckunte at gmail.com
Thu Jan 22 12:40:07 GMT 2009


Hi -

I was wondering if any of you could help me with a unique problem I
have with regards to a plugin I wrote sometime ago:
http://wordpress.org/extend/plugins/small-caps/

This plugin takes capitalized words, and turns them into small caps
using the <abbr> html tag. ( More here:
http://ckunte.com/archives/small-caps ). Please see the basic plugin
code below.

-- start of code --

function ckunte_smallcaps($text) {
        $search = "/\b([A-Z][A-Z0-9]{2,})\b/";
        $replace = "<abbr>$1</abbr>";
        $text = preg_replace($search,$replace,$text);
        return $text;
}
//
if (function_exists('add_filter')) {
        add_filter('the_content', 'ckunte_smallcaps');
}

-- end of code --

This code works well--with an exception and an unintended consequence.
For example, if a URL has a Capital words in them like for example
below,

http://somesite.com/2007/04/i-worship-GANDHI/

then this plugin does, yes you guessed it:

http://somesite.com/2007/04/i-worship-<abbr>GANDHI</abbr>/

And thus potentially breaking the link.

Could anyone suggest how I could escape the words inside <a> tag please?

Grateful for your help,
-- 
Chetan, ckunte.com


More information about the wp-hackers mailing list