Inspired by a post on dive into mark, TagifyThis is a little function I wrote a while ago, that surrounds specified strings with specified tags and attributes.
The first use I made of it was for acronyms, but it can be used for just any tag.
You give it a string, and a list of lines like "literal" tag attribute "value", and then whenever it sees literal in the string it converts it to <tag attribute="value">literal<tag>.

When I first blogged about it, it was broken because of a bug in PHP’s handling of PREG_SET_ORDER, and because it could only handle one list of strings and tags. It just wasn’t flexible. Now PHP is fixed, and TagifyThis handles any list of replacements that you throw at it.

More documentation in the source: tagifythis.phps.

2 responses

  1. Looks good to me: useful, and nicely done.

    Which is a good thing, since with that relative link triggering whatever it is that causes your server to tack on a PHP session id when wget, curl, or Bloglines comes calling for your feed, I’ll be seeing this post as unread every single time Bloglines refreshes until it falls off the bottom of your feed :(

    #1 Phil Ringnalda2004/03/14 at 7:02

  2. You must have session.use_trans_sid on in php.ini. If you have it on for a reason, like you need it somewhere,

    php_value session.use_trans_sid 0

    in .htaccess in the directory where your feeds are generated ought to stop it slapping on the session id for things that don’t accept cookies.

    #2 Phil Ringnalda2004/03/24 at 5:25

Your words

Required fields:
Are marked by this sign: *
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
On comment spam/irrelevance:
Your comment may be moderated or considered as spam by the leprechauns running this server. If you get a 412 error or a mean message, it may be that they thought it was spam: try wording the comment differently or remind me to put up a contact form so you can warn me about the problem.
Of course, once the leprechauns are done doing their magic, I reserve the right to delete any comment for any reason.