[Catalyst] create search engine friendly uri from string

Ashley apv at sedition.com
Tue Dec 16 02:28:03 GMT 2008


On Dec 15, 2008, at 1:23 PM, Moritz Onken wrote:
>
> Am 15.12.2008 um 21:53 schrieb Johannes Plunien:
>
>>> 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";
>

Just a caveat that should be in the doc you end up with if not  
possible in the code. URIs are supposed to be unique to a resource.  
Titles of articles and pages are not (necessarily). The end user/dev  
will have to check for duplicates against the data and append a -II  
or -2, and so on.

-Ashley




More information about the Catalyst mailing list