|
|
 |
August 13th, 2008, 08:24 PM
|
#1
|
|
New Member
Join Date: Aug 2008
Location: Atlanta
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Replace space with hyphen in URL
Hi, I need to replace the spaces in my URL's with hyphens, eg.
George%20III%20Mahogany%20Dining%20Table/23736. asp
becomes George-III-Mahogany-Dining-Table/23736. asp
Here is the bit of code that I am using to generate the URL's:
<a href="/furniture/antique/<% = prodname %>/<% = prodidnum %>. asp"><% = prodname %></a>
Those are SQL database values. Basically, I need some way to make prodname (George III Mahogany Dining Table) into George-III-Mahogany-Dining-Table just for the URL. I wonder if there is a way for me to add hyphens to prodname when adding items to the database and then name the result prodname2 and then just call that for the URL? I have no idea how to do that though.
I am using classic APS, IIS 5.0, Windows Server 2000 and ISAPI_Rewrite. I am on a dedicated server but my SQL database is in a shared environment.
|
|
|
August 14th, 2008, 12:31 AM
|
#2
|
|
New Member
Join Date: Aug 2008
Location: Atlanta
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: Replace space with hyphen in URL
I got some help and it's fixed! Following is the code that did the trick:
Code:
<a href="/furniture/antique/<% = (replace(prodname, " ", "-"))%>/<% = prodidnum %>.asp"><% = prodname %></a>
|
|
|
March 7th, 2009, 08:26 PM
|
#3
|
|
New Member
Join Date: Feb 2009
Location: Brasil
Age: 28
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Re: Replace space with hyphen in URL
Code:
'-----------------------------------------------------
'Funcao: FormataStringToUrl(ByVal Texto)
'Sinopse: Substitui os caracteres para formar uma
' string que possa ser utilizada na URL
'Parametro: Texto: Texto a ser transformado
'Retorno: String
'Autor: Heber ALmeida - www.heberonline.com.br
'-----------------------------------------------------
Function FormataStringToUrl(ByVal Texto)
FormataStringToUrl = Replace(Replace(LCase(Texto), " ", " "), "\'", "")
FormataStringToUrl = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(FormataStringToUrl, " ", "-"), "á", "a"), "é", "e"), "í", "i"), "ó", "o"), "ú", "u"), "ã", "a"), "â", "a"), "à", "a"), "ê", "e"), "ô", "o"), "ç", "c"), "/", ""), "'", ""), """", ""), "[", ""), "]", ""), "&", "-"), "#", ""), "+", ""), "{", ""), "}", ""), "ù", "u"), "ò", "o"), ".", ""), "?", ""), "!", ""), ":", ""), "´", ""), "`", ""), "õ", "o"), "\", "")
FormataStringToUrl = Replace(Replace(Replace(FormataStringToUrl, "û", "u"), "¢", "c"), "¡", "i")
FormataStringToUrl = Replace(Replace(Replace(FormataStringToUrl, "£", "e"), "¤", ""), "¥", "y")
FormataStringToUrl = Replace(Replace(Replace(FormataStringToUrl, "¦", ""), "ª", "a"), "æ", "ae")
FormataStringToUrl = Replace(Replace(Replace(Replace(FormataStringToUrl, "ë", "e"), "ì", "ì"), "ð", "o"), "Ä", "a")
FormataStringToUrl = Replace(Replace(Replace(Replace(FormataStringToUrl, "ñ", "n"), "ø", "o"), "ý", "y"), " ", " ")
FormataStringToUrl = Replace(Replace(Replace(Replace(FormataStringToUrl, "þ", "p"), "€", "e"), "ÿ", "y"), "²", "z")
FormataStringToUrl = Replace(FormataStringToUrl, "%", "")
FormataStringToUrl = Replace(FormataStringToUrl, "---", "-")
End Function
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|