From 1d7c1b6f69a8b6b10fd304730b95eeeaa6654098 Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Thu, 23 Nov 2006 21:30:36 +0000 Subject: [PATCH] Add string2id function that is useful in generating HTML id attributes from random data. --- cgi-bin/dispatcher.pl | 1 + lib/Packages/CGI.pm | 7 +++++++ 2 files changed, 8 insertions(+) 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 { -- 2.39.2