[Catalyst] create search engine friendly uri from string

Johannes Plunien plu at pqpq.de
Mon Dec 15 20:53:44 GMT 2008


> On 15.12.2008, at 21:22, Jim Spath wrote:
>
>> You might also want to add these two to the end:
>>
>> =~ s/--+/-/g;
>> =~ s/-$//g;
>>
>> Scott McWhirter wrote:
>>> $str =~ s{\W}{}g;
>>> $str = lc($str);
>>> $str =~ s{\s+}{-}g;

My not very elegant, but working solution:

my $str = "  Beta Launch Invites: Kwyno Brings The Web Into Your IM  
And (Soon) SMS Inboxes  ";
$str =~ s/^\s+|\s+$//g;
$str =~ s/\W/ /g;
$str =~ s/\s{1,}/ /g;
$str =~ s/\s/-/g;
$str = lc($str);

print "$str\n";

--
Johannes Plunien | mailto:plu at pqpq.de | http://www.pqpq.de/contact/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2436 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20081215/e05878b9/smime.bin


More information about the Catalyst mailing list