in reply to Re^2: WordPress 'sanitize_title'
in thread WordPress 'sanitize_title'

Once again you just give up too easily. PHP is no harder than Perl. You're just being lazy.
sanitize_title applied to a post title by the sanitize_title function, after stri +pping out HTML tags. wordpress/wp-includes/taxonomy.php: $value = apply_filters("pre +_term_$field", $value, $taxonomy); wordpress/wp-includes/default-filters.php:$filters = array('pre_term_s +lug'); wordpress/wp-includes/plugin.php:function apply_filters($tag, $value) +{ wordpress/wp-includes/formatting.php:function sanitize_file_name( $nam +e ) { // Like sanitize_title, but with periods wordpress/wp-includes/formatting.php:function sanitize_title($title, $ +fallback_title = '') { wordpress/wp-includes/formatting.php: $title = apply_filters('sanit +ize_title', $title); wordpress/wp-includes/taxonomy.php: $args['query_var'] = saniti +ze_title_with_dashes($args['query_var']); wordpress/wp-includes/taxonomy.php: $args['rewrite']['slug' +] = sanitize_title_with_dashes($taxonomy); wordpress/wp-includes/taxonomy.php: $value = sanitize_title($va +lue); wordpress/wp-includes/taxonomy.php: $slug = sanitize_title($slu +g); wordpress/wp-includes/taxonomy.php: if ( '' === $slug = sanitize_ti +tle($term) ) wordpress/wp-includes/taxonomy.php: $slug = sanitize_title($nam +e); wordpress/wp-includes/taxonomy.php: $slug = sanitize_title($slu +g, $term_id); wordpress/wp-includes/taxonomy.php: $slug = sanitize_title($nam +e); wordpress/wp-includes/taxonomy.php: $slug = sanitize_title($nam +e, $term_id); function add_filter($tag, $function_to_add, $priority = 10, $accepted_ +args = 1) { global $wp_filter, $merged_filters; $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priorit +y); $wp_filter[$tag][$priority][$idx] = array('function' => $function_ +to_add, 'accepted_args' => $accepted_args); unset( $merged_filters[ $tag ] ); return true; } // Slugs $filters = array('pre_term_slug'); foreach ( $filters as $filter ) { add_filter($filter, 'sanitize_title'); } add_filter('sanitize_title', 'sanitize_title_with_dashes'); function sanitize_title_with_dashes($title) { $title = strip_tags($title); // Preserve escaped octets. $title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $ +title); // Remove percent signs that are not part of an octet. $title = str_replace('%', '', $title); // Restore octets. $title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $ +title); $title = remove_accents($title); if (seems_utf8($title)) { if (function_exists('mb_strtolower')) { $title = mb_strtolower($title, 'UTF-8'); } $title = utf8_uri_encode($title, 200); } $title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = preg_replace('/[^%a-z0-9 _-]/', '', $title); $title = preg_replace('/\s+/', '-', $title); $title = preg_replace('|-+|', '-', $title); $title = trim($title, '-'); return $title; }
http://www.w3schools.com/php/func_string_strip_tags.asp
http://www.php.net/preg_replace
http://www.php.net/strip_tags
http://www.php.net/trim
http://www.php.net/strtolower
WordPress › Support » How does WP remove accents from Polish characters?
http://codex.wordpress.org/Function_Reference_2.0.x

http://adambrown.info/p/wp_hooks/hook/sanitize_title?version=2.6&file=wp-includes/formatting.php
http://postedpost.com/2008/06/22/hack-wordpress-sanitize-title-function/
http://postedpost.com/2008/06/23/ultimate-wordpress-post-name-url-sanitize-solution/

Replies are listed 'Best First'.
Re^4: WordPress 'sanitize_title'
by Klammer (Acolyte) on Sep 01, 2008 at 17:13 UTC
    > You're just being lazy.
    In defense I can only say, that I'm not a good perl scripter too. :)

    I'm really trying hard. I don't expect anybody to write this for me in case you fear I'm that sort of guy.

    As far as I understand your posted code, sanitize_title_with_dashes is the function to look for. Finally some string manipulation. :)

    Thanks for all the other helpful links. I'll have a look at it and will try to convert sanitize_title_with_dashes into perl code.

    Cheers Klammer