{"id":796,"date":"2013-03-28T18:52:43","date_gmt":"2013-03-28T17:52:43","guid":{"rendered":"http:\/\/fabioinvernizzi.com\/blog\/?p=796"},"modified":"2013-04-16T09:45:17","modified_gmt":"2013-04-16T08:45:17","slug":"dasherize","status":"publish","type":"post","link":"https:\/\/fabioinvernizzi.com\/blog\/2013\/03\/28\/dasherize\/","title":{"rendered":"dasherize"},"content":{"rendered":"<p>i had to write a &#8220;dasherize&#8221; function to generate SEO friendly url and so i found the power of unicode normalization&#8230;<\/p>\n<p><code>#!\/usr\/bin\/perl<\/p>\n<p>use warnings;<br \/>\nuse strict;<br \/>\nuse utf8;<br \/>\nuse Unicode::Normalize;<\/p>\n<p>my $string = 'accentate \u00ab\u00e0\u00e8\u00ec\u00f2\u00f9\u00bb e &#8220;euro&#8221; (\u00a4\u00e7) {\u00b9\u00b2\u00b3} [prova]';<br \/>\nmy $length = 200;<\/p>\n<p>binmode(STDOUT, \":utf8\");<\/p>\n<p>print \"$string\\n\";<\/p>\n<p>$string = NFKD($string);<br \/>\n$string =~ s\/\\pM\/\/og;<\/p>\n<p>$string =~ s\/[^a-z0-9]+\/-\/gi;<br \/>\n$string =~ s\/^(.{1,$length}).*\/\\L$1\/;<br \/>\n$string =~ s\/-[^-]*?$\/\/;<\/p>\n<p>print \"$string\\n\";<br \/>\n<\/code><\/p>\n<p>and here is the output:<\/p>\n<p><code>fabio@gnu64:~\/tmp$ .\/dasherize<br \/>\naccentate \u00ab\u00e0\u00e8\u00ec\u00f2\u00f9\u00bb e &#8220;euro&#8221; (\u00a4\u00e7) {\u00b9\u00b2\u00b3} [prova]<br \/>\naccentate-aeiou-e-euro-c-123-prova<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>i had to write a &#8220;dasherize&#8221; function to generate SEO friendly url and so i found the power of unicode normalization&#8230; #!\/usr\/bin\/perl use warnings; use strict; use utf8; use Unicode::Normalize; my $string = &#8216;accentate \u00ab\u00e0\u00e8\u00ec\u00f2\u00f9\u00bb e &#8220;euro&#8221; (\u00a4\u00e7) {\u00b9\u00b2\u00b3} [prova]&#8217;; my $length = 200; binmode(STDOUT, &#8220;:utf8&#8221;); print &#8220;$string\\n&#8221;; $string = NFKD($string); $string =~ s\/\\pM\/\/og; $string &hellip; <a href=\"https:\/\/fabioinvernizzi.com\/blog\/2013\/03\/28\/dasherize\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">dasherize<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[2],"tags":[75,49,77,76],"class_list":["post-796","post","type-post","status-publish","format-standard","hentry","category-me","tag-code","tag-perl","tag-seo","tag-unicode"],"_links":{"self":[{"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/posts\/796"}],"collection":[{"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/comments?post=796"}],"version-history":[{"count":4,"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/posts\/796\/revisions"}],"predecessor-version":[{"id":803,"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/posts\/796\/revisions\/803"}],"wp:attachment":[{"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/media?parent=796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/categories?post=796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabioinvernizzi.com\/blog\/wp-json\/wp\/v2\/tags?post=796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}