From: Frank Lichtenheld Date: Thu, 23 Nov 2006 21:30:36 +0000 (+0000) Subject: Add string2id function that is useful in generating HTML id attributes X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=1d7c1b6f69a8b6b10fd304730b95eeeaa6654098;p=deb%2Fpackages.git Add string2id function that is useful in generating HTML id attributes from random data. --- diff --git a/cgi-bin/dispatcher.pl b/cgi-bin/dispatcher.pl index 45d1b46..e34f0e3 100755 --- a/cgi-bin/dispatcher.pl +++ b/cgi-bin/dispatcher.pl @@ -269,6 +269,7 @@ $page_content{make_url} = sub { return &Packages::CGI::make_url(@_) }; $page_content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') }; $page_content{uri_escape} = sub { return URI::Escape::uri_escape(@_) }; $page_content{quotemeta} = sub { return quotemeta($_[0]) }; +$page_content{string2id} = sub { return &Packages::CGI::string2id(@_) }; print $input->header( -charset => $charset ); diff --git a/lib/Packages/CGI.pm b/lib/Packages/CGI.pm index 9a8584f..b092352 100644 --- a/lib/Packages/CGI.pm +++ b/lib/Packages/CGI.pm @@ -333,6 +333,13 @@ sub printindexline { # return ( $start, $end ); #} +sub string2id { + my $string = "@_"; + + $string =~ s/[^\w]/_/g; + return $string; +} + our ( %url_params, %query_params ); sub init_url {