Hi perlmonks

After writing a blog post and publishing it, WordPress transforms the given title to a permalink.

Title: "Test title"
Permalink: http://blogname.com/YEAR/MONTH/DAY/test-title

WordPress does some magic to transform the given title (strips out certain characters, replaces others, ...). I checked the WordPress source code, but all I could find was a function called sanitize_title within wp_includes/formatting.php (I'm not good at PHP)
function sanitize_title($title, $fallback_title = '') { $title = strip_tags($title); $title = apply_filters('sanitize_title', $title); if ( '' === $title || false === $title ) $title = $fallback_title; return $title; }
I want to write a script that supports me in writing a blog post offline by generating some html code which I could paste easily in the online editor later.

The thing is, I need the "sanitized title" within some URLs within the generated html code. So Perl has to sanitize the given title in the same way as WordPress to generate valid urls.

I've searched google and Super Search but couldn't find anything useful. Has anybody already written a perl version of "sanitize_title" or a clue where WordPress does its magic to convert a user given title to its final form?

My goal would be a function which I can pass my title to and which returns the sanitized title.

Cheers Klammer

In reply to WordPress 'sanitize_title' by Klammer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.