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

scribu scribu at gmail.com
Thu Jan 22 12:54:57 GMT 2009


You would have to not select "words" that begin with '.+://' or something.

Instead of using a filter that has to parse the content on each page load,
wouldn't it be better to add the abbr tags just before the post is saved to
the database?

On Thu, Jan 22, 2009 at 2:40 PM, Chetan Kunte <ckunte at gmail.com> wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
http://scribu.net


More information about the wp-hackers mailing list