URL Slugs from 1000's of Titles?

Jizzlobber

Moist
Mar 7, 2007
3,620
133
0
I've got a non-WP site using a script that has a directory feature. The listing submission form creates title slugs on the fly, placing them in a table column for use for other functions as well. Naturally, I want to import thousands of records at once - what's the quickest way to modify the titles so it's already done on import?
 


OK, here's the code I found to create a function and do the conversion right in Excel. Worked fine for what I was doing. Not sure of how it might handle diacritics - if anyone knows, then chime in.

Code:
Function CleanPostName(ByVal sPostName As String, _
    Optional ByVal bCreateURL As Boolean = False) As String
   
    Dim idx As Long
    Dim sNew As String
   
    For idx = 1 To Len(sPostName)
        Select Case Asc(Mid$(sPostName, idx, 1))
            Case 48 To 57 'leave numbers
                sNew = sNew & Mid$(sPostName, idx, 1)
            Case 65 To 90, 97 To 122 'convert letters to lowercase
                sNew = sNew & LCase$(Mid$(sPostName, idx, 1))
            Case 45 'leave dashes - no two dashes
                If idx> 1 And Right$(sNew, 1) <> Chr$(45) Then
                    sNew = sNew & Mid$(sPostName, idx, 1)
                End If
            Case 32 'convert spaces to dashes - multiple spaces = one dash
                If idx> 1 And Right$(sNew, 1) <> Chr$(45) Then
                    sNew = sNew & Chr$(45)
                End If
        End Select
    Next idx
       
    If bCreateURL Then
        sNew = "http://www.wickedfire.com/makemonies/" & sNew & "/"
    End If
   
    CleanPostName = sNew
       
End Function