Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

fael

Página de busca em arquivos HTML

Recommended Posts

Pessoal,

 

Eu peguei um código pronto para busca em documentos HTML, funciona muito bem só que não consegue encontrar palavras com acento, esse script era em inglês e eu o traduzi ele pode ser conferido no endereço http://ecosol.gaia.org.br/busca/site_search.asp.

 

Alguém aí sabe me dizer como eu faço para inserir uma função para fazer o sistema reconhecer esses acentos, ou então ele retirar os acentos dos HTML's só para buscar?

 

Desde já agradeço pela ajuda.

 

Um Abraço,

 

Fael

Desenvolvedor Web

rafael@cenex.com.br

Compartilhar este post


Link para o post
Compartilhar em outros sites

Como se faz este tipo de busca pelas páginas?´Tem algum jeito de diferir automaticamente uma busca de palavra e frase, sem ter que usar um check?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Segue o código:<% Option Explicit %><% 'Set the response buffer to trueResponse.Buffer = True 'Dimension global variablesDim fsoObjectDim fldObjectDim sarySearchWordDim strSearchWordsDim blnIsRootDim strFileURLDim strServerPathDim intNumFilesShownDim intTotalFilesSearchedDim intTotalFilesFoundDim intFileNumDim intPageLinkLoopCounterDim sarySearchResults(500,2)Dim intDisplayResultsLoopCounterDim intResultsArrayPositionDim blnSearchResultsFoundDim strFilesTypesToSearchDim strBarredFoldersDim strBarredFilesDim blnEnglishLanguage' -------------------------- Change the following line to the number of results you wish to have on each page ------------------------------------Const intRecordsPerPage = 10 'change this to the number of results to show on each page' --------------------- Place the names of the files types you want searching in the following line sepeararted by commas --------------------------strFilesTypesToSearch = "htm,html,asp,shtml" ' --------------------- Place the names of the folders you don't want searched in the following line spearated by commas --------------------------strBarredFolders = "cgi_bin,_bin" 'cgi_bin and _bin have been put in here as examples, but you can put any folders in here' ---------- Place the names of the files you don't want searched in the following line spearated by commas include the file extension -------------strBarredFiles = "adminstation.htm,no_allowed.asp" 'adminstration.htm and not_allowed.asp have been put in as an examples' -------------------- Set this boolean to False if you are not using an English language web site --------------------------------------------------blnEnglishLanguage = True 'True = English \ False = Other language'-----------------------------------------------------------------------------------------------------------------------------------------------------'Initalise variablesintTotalFilesSearched = 0%><html><head><title>Ecosust</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" href="estilo.css" type="text/css"><!-- Desenvolvido por Rafael Szarblewski - Desenvolvedor web --> <!-- Check the from is filled in correctly before submitting --><script language="JavaScript"><!-- Hide from older browsers...//Check the form before submittingfunction CheckForm () { //Check for a word to search if (document.frmSiteSearch.search.value==""){ alert("Por favor, digite alguma palavra para a busca!"); document.frmSiteSearch.search.focus(); return false; } return true}// --></script> </head><body><div align="center"><IMG src="ec1.gif" width="370" height="121" align="center"></div><form method="get" name="frmSiteSearch" action="site_search.asp" onSubmit="return CheckForm();"> <table cellpadding="0" cellspacing="0" width="90%" align="center"> <tr> <td height="66" width="165" align="right" rowspan="3" valign="middle">  </td> <td height="66" width="15" align="right" rowspan="3" valign="middle"> </td> <td class="arial" height="4" width="571"> <p>Digite abaixo o que deseja procurar:</td> </tr> <tr> <td class="normal" height="2" width="571"> <input type="TEXT" class="txt" name="search" maxlength="50" size="36" value="<% =Request.QueryString("search") %>"> <input type="submit" class="btn" value="Buscar >>" name="submit"> </td> </tr> <tr> <td class="normal" height="34" width="571" valign="top"> <font color="#006699" size="2" face="Verdana, Arial, Helvetica, sans-serif">Buscar por:</font> <input type="radio" name="mode" value="allwords" CHECKED> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Palavra</font> <input type="radio" name="mode" value="phrase" CHECKED> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Frase</font></td> </tr> </table></form><%'Read in all the search words into one variablestrSearchWords = Trim(Request.QueryString("search"))'Read in all the search words into one variablestrSearchWords = Trim(Request.QueryString("search"))'If the site is in English then use the server HTML encode methodIf blnEnglishLanguage = True Then 'Replace any HTML tags with the HTML codes for the same characters (stops people entering HTML tags) strSearchWords = Server.HTMLEncode(strSearchWords)'If the site is not english just change the script tagsElse 'Just replace the script tag <> with HTML encoded < and > strSearchWords = Replace(strSearchWords, "<", "<", 1, -1, 1) strSearchWords = Replace(strSearchWords, ">", ">", 1, -1, 1)End If'Slit each word to be searched up and place in an arraysarySearchWord = Split(Trim(strSearchWords), " ")'Read the file number to show fromintFileNum = CInt(Request.QueryString("FileNumPosition"))'Set the number of files shown so far to the file number read in aboveintNumFilesShown = intFileNum'Create the file system objectSet fsoObject = Server.CreateObject("Scripting.FileSystemObject")'If there is no words entered by the user to search for then dont carryout the file search routineIf NOT Request.QueryString("search") = "" Then 'Get the path and the root folder to be searched Set fldObject = fsoObject.GetFolder(Server.MapPath("./")) 'Read in the server path to this ASP script strServerPath = fldObject.Path & "\" 'Set to true as this is searching the root directory blnIsRoot = True 'Call the search sub prcedure Call SearchFile(fldObject) 'Reset server variables Set fsoObject = Nothing Set fldObject = Nothing 'Call the Bubble Sort procedure to sort the results into highest matches first Call SortResultsByNumMatches(sarySearchResults, intTotalFilesFound) 'Display the HTML table with the results status of the search or what type of search it is Response.Write vbCrLf & " <table width=""98%"" border=""0"" cellspacing=""1"" cellpadding=""1"" align=""center"" bgcolor=""#CCCCCC"">" Response.Write vbCrLf & " <tr>" 'Display that there where no matching records found If blnSearchResultsFound = False Then Response.Write vbCrLf & " <td><p> Procurando por <b>" & strSearchWords & "</b>.<p>    Não foi encontrado nenhum resultado para a busca.</td>" 'Else Search went OK so display how many records found Else Response.Write vbCrLf & " <td><p> Procurando por <b>" & strSearchWords & "</b>.   Resultado: " & intFileNum + 1 & " - " & intNumFilesShown & " de " & intTotalFilesFound & ".</td>" End If 'Close the HTML table with the search status Response.Write vbCrLf & " </tr>" Response.Write vbCrLf & " </table>" 'HTML table to display the search results or an error if there are no results Response.Write vbCrLf & " <table width=""95%"" border=""0"" cellspacing=""1"" cellpadding=""1"" align=""center"">" Response.Write vbCrLf & " <tr>" Response.Write vbCrLf & " <td>" 'If no results are found then display an error message If blnSearchResultsFound = False Then 'Write HTML displaying the error Response.Write vbCrLf & " <br>" Response.Write vbCrLf & " Sua Busca - <b>" & strSearchWords & "</b> - não foi possível ser encontrada!" Response.Write vbCrLf & " <br><br>" Response.Write vbCrLf & " Sugestões:" Response.Write vbCrLf & " <br>" Response.Write vbCrLf & " <ul><li>Verifique se você digitou corretamente.<li>Tente palavras diferentes das que você digitou.<li>Tente procurar por palavras mais comuns.<li>Tente menos palavras.</ul>" 'Else display the results Else 'Loop round to display each result within the search results array For intDisplayResultsLoopCounter = (intFileNum + 1) to intNumFilesShown Response.Write vbCrLf & " <br>" Response.Write vbCrLf & " " & sarySearchResults(intDisplayResultsLoopCounter,1) Response.Write vbCrLf & " <br>" Next End If 'Close the HTML table displaying the results Response.Write vbCrLf & " </td>" Response.Write vbCrLf & " </tr>" Response.Write vbCrLf & " </table>"End If 'Display an HTML table with links to the other search resultsIf intTotalFilesFound > intRecordsPerPage then 'Display an HTML table with links to the other search results Response.Write vbCrLf & " <br>" Response.Write vbCrLf & " <table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"" align=""center"">" Response.Write vbCrLf & " <tr>" Response.Write vbCrLf & " <td>" Response.Write vbCrLf & " <table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">" Response.Write vbCrLf & " <tr>" Response.Write vbCrLf & " <td width=""50%"" align=""center"">" Response.Write vbCrLf & " Páginas do resultado:  " 'If the page number is higher than page 1 then display a back link If intNumFilesShown > intRecordsPerPage Then Response.Write vbCrLf & " <a href=""site_search.asp?FileNumPosition=" & intFileNum - intRecordsPerPage & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self""><< Anterior</a> " End If 'If there are more pages to display then display links to all the search results pages If intTotalFilesFound > intRecordsPerPage Then 'Loop to diplay a hyper-link to each page in the search results For intPageLinkLoopCounter = 1 to CInt((intTotalFilesFound / intRecordsPerPage) + 0.5) 'If the page to be linked to is the page displayed then don't make it a hyper-link If intFileNum = (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage Then Response.Write vbCrLf & " " & intPageLinkLoopCounter Else Response.Write vbCrLf & "  <a href=""site_search.asp?FileNumPosition=" & (intPageLinkLoopCounter * intRecordsPerPage) - intRecordsPerPage & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self"">" & intPageLinkLoopCounter & "</a>  " End If Next End If 'If it is Not the last of the search results than display a next link If intTotalFilesFound > intNumFilesShown then Response.Write vbCrLf & "  <a href=""site_search.asp?FileNumPosition=" & intNumFilesShown & "&search=" & Replace(strSearchWords, " ", "+") & "&mode=" & Request.QueryString("mode") & """ target=""_self"">Próximo >></a>" End If 'Finsh HTML the table Response.Write vbCrLf & " </td>" Response.Write vbCrLf & " </tr>" Response.Write vbCrLf & " </table>" Response.Write vbCrLf & " </td>" Response.Write vbCrLf & " </tr>" Response.Write vbCrLf & " </table>" End If %> <br> <div align="center"> <table width="98%" border="0" cellspacing="1" cellpadding="1" bgcolor="#CCCCCC" align="center"> <tr> <td width="47%" height="18"> <p><% = intTotalFilesSearched %> documentos encontrados no total. </td> <td width="53%" align="right" height="18"><p>Desenvolvido por <a href="http://www.faelsz.pop.com.br">Fael Soluções Digitais</a></td> </tr> </table> </div><br></body></html><%'Sub procedure to do the searchPublic Sub SearchFile(fldObject) 'Dimension local variabales Dim objRegExp 'Regular Expersions object Dim objMatches 'Holds the matches collection of the regular expresions object Dim filObject 'File object Dim tsObject 'Text stream object Dim subFldObject 'Sub folder object Dim strFileContents 'Holds the contents of the file being searched Dim strPageTitle 'Holds the title of the page Dim strPageDescription 'Holds the description of the page Dim strPageKeywords 'Holds the keywords of the page Dim intSearchLoopCounter 'Loop counter to search all the words in the array Dim intNumMatches 'Holds the number of matches Dim blnSearchFound 'Set to true if the search words are found 'Error handler On Error Resume Next 'Loop to search each file in the folder For Each filObject in fldObject.Files 'Check the file extension to make sure the file is of the extension type to be searched If InStr(1, strFilesTypesToSearch, fsoObject.GetExtensionName(filObject.Name), vbTextCompare) > 0 Then 'Check to make sure the file about to be searched is not a barred file if it is don't search the file If NOT InStr(1, strBarredFiles, filObject.Name, vbTextCompare) > 0 Then 'Initalise the search found variable to flase blnSearchFound = False 'Initalise the number of matches variable intNumMatches = 0 'Create the regular expresions object Set objRegExp = New RegExp 'Set the regular exprsion object to read all cases of the occurance not just the first objRegExp.Global = True 'Set the regular expression object to ignore case objRegExp.IgnoreCase = True 'Open the file for searching Set tsObject = filObject.OpenAsTextStream 'Read in the contents of the file strFileContents = tsObject.ReadAll 'Read in the title of the file strPageTitle = Server.HTMLEncode(GetFileMetaTag("<title>", "</title>", strFileContents)) 'Read in the description meta tag of the file strPageDescription = Server.HTMLEncode(GetFileMetaTag("<meta name=""description"" content=""", """>", strFileContents)) 'Read in the keywords of the file strPageKeywords = Server.HTMLEncode(GetFileMetaTag("<meta name=""keywords"" content=""", """>", strFileContents)) 'Set the pattern using regular expressions to srip any HTML tags objRegExp.Pattern = "<[^>]*>" 'Strip HTML tags from the contects of the file to be searched strFileContents = objRegExp.Replace(strFileContents,"") 'Put the tittle, description and the keywords back into the file to be searched strFileContents = strFileContents & " " & strPageTitle & " " & strPageDescription & " " & strPageKeywords 'If the user has choosen to search by phrase If Request.QueryString("mode") = "phrase" Then 'Set the pattern to search for objRegExp.Pattern = "\b" & strSearchWords & "\b" 'Search the file for the phrase Set objMatches = objRegExp.Execute(strFileContents) 'Check to see if the phrase has been found If objMatches.Count > 0 Then 'Get the number of times the phrase is matched intNumMatches = objMatches.Count 'If the search is found then set the search found variable to true blnSearchFound = True End If 'Else the search is either by all or any words Else 'If the search is by all words then initialise the search found variable to true If Request.QueryString("mode") = "allwords" then blnSearchFound = True 'Loop round to search for each word to be searched For intSearchLoopCounter = 0 to UBound(sarySearchWord) 'Set the pattern to search for objRegExp.Pattern = "\b" & sarySearchWord(intSearchLoopCounter) & "\b" 'Search the file for the search words Set objMatches = objRegExp.Execute(strFileContents) 'Check to see if any of the words have been found If objMatches.Count > 0 Then 'Get the number of times the search word is matched intNumMatches = intNumMatches + objMatches.Count 'If the search word is found and the search is for any words then set the search found variable to true If Request.QueryString("mode") = "anywords" then blnSearchFound = True Else 'If the search word is not found and the search is for all words then set the search found variable back to false as one of the words has not been found If Request.QueryString("mode") = "allwords" then blnSearchFound = False End If Next End If 'Calculate the total files searched intTotalFilesSearched = intTotalFilesSearched + 1 'If the page contains no title then Page Title variable the appropriate message to display If strPageTitle = "" Then strPageTitle = "Sem título." 'If the page contains no title then Page Description variable the appropriate message to display If strPageDescription = "" Then strPageDescription = "Pagina sem descrição." 'If the search found variable is true then display the results If blnSearchFound = True Then 'Calculate the total files found intTotalFilesFound = intTotalFilesFound + 1 'Check that the file shown is between the the files shown so far and the maximum files to show per page If intNumFilesShown < (intRecordsPerPage + intFileNum) and intTotalFilesFound > intNumFilesShown Then 'Calculate the number of results shown intNumFilesShown = intNumFilesShown + 1 End If 'Place the search results into the saerch results array 'Calculate the array position of the results array intResultsArrayPosition = intResultsArrayPosition + 1 'Set the search results found boolean to true blnSearchResultsFound = True 'If the file is in the root directory then If blnIsRoot = True Then 'Place the search results into the search results array sarySearchResults(intResultsArrayPosition,1) = "<a href=""./" & filObject.Name & """ target=""_self"">" & strPageTitle & "</a>" 'Else it is not in the root directiory Else 'Place the search results into the search results array sarySearchResults(intResultsArrayPosition,1) = "<a href=""./" & strFileURL & fldObject.Name & "/" & filObject.Name & """ target=""_self"">" & strPageTitle & "</a>" End If 'Place the rest of the search results in the search results array sarySearchResults(intResultsArrayPosition,1) = sarySearchResults(intResultsArrayPosition,1) & vbCrLf & " <br>" & strPageDescription sarySearchResults(intResultsArrayPosition,1) = sarySearchResults(intResultsArrayPosition,1) & vbCrLf & " <font size=""2"" color=""#0000FF""><br><i>  Última atualização: " & FormatDateTime(filObject.DateLastModified, VbLongDate) & "  -  Tamanho: " & CInt(filObject.Size / 1024) & "kb</i></font>" 'Read in the number of search word matches into the second part of the two dimensional array sarySearchResults(intResultsArrayPosition,2) = intNumMatches End If 'Reset the Regular Expression object Set objRegExp = Nothing 'Close the text stream object tsObject.Close End If End If Next 'Loop to search through the sub folders within the site For Each subFldObject In FldObject.SubFolders 'Check to make sure the folder about to be searched is not a barred folder if it is then don't search If NOT InStr(1, strBarredFolders, subFldObject.Name, vbTextCompare) > 0 Then 'Set to false as we are searching sub directories blnIsRoot = False 'Get the server path to the file strFileURL = fldObject.Path & "\" 'Turn the server path to the file into a URL path to the file strFileURL = Replace(strFileURL, strServerPath, "") 'Replace the NT backslash with the internet forward slash in the URL to the file strFileURL = Replace(strFileURL, "\", "/") 'Replace the spaces in the URL to the file with Internet friendly %20 strFileURL = Replace(strFileURL, " ", "%20") 'Call the search sub prcedure to search the web site Call SearchFile(subFldObject) End If Next 'Reset server variables Set filObject = Nothing Set tsObject = Nothing Set subFldObject = NothingEnd Sub'Sub procedure to sort the array using a Bubble Sort to place highest matches firstPrivate Sub SortResultsByNumMatches(ByRef sarySearchResults, ByRef intTotalFilesFound) 'Dimension variables Dim intArrayGap 'Holds the part of the array being sorted Dim intIndexPosition 'Holds the Array index position being sorted Dim intTempResultsHold 'Temperary hold for the results if they need swapping array positions Dim intTempNumMatchesHold 'Temperary hold for the number of matches for the result if they need swapping array positions Dim intPassNumber 'Holds the pass number for the sort 'Loop round to sort each result found For intPassNumber = 1 To intTotalFilesFound 'Shortens the number of passes For intIndexPosition = 1 To (intTotalFilesFound - intPassNumber) 'If the Result being sorted hass less matches than the next result in the array then swap them If sarySearchResults(intIndexPosition,2) < sarySearchResults((intIndexPosition+1),2) Then 'Place the Result being sorted in a temporary variable intTempResultsHold = sarySearchResults(intIndexPosition,1) 'Place the Number of Matches for the result being sorted in a temporary variable intTempNumMatchesHold = sarySearchResults(intIndexPosition,2) 'Do the array position swap 'Move the next Result with a higher match rate into the present array location sarySearchResults(intIndexPosition,1) = sarySearchResults((intIndexPosition+1),1) 'Move the next Number of Matches for the result with a higher match rate into the present array location sarySearchResults(intIndexPosition,2) = sarySearchResults((intIndexPosition+1),2) 'Move the Result from the teporary holding variable into the next array position sarySearchResults((intIndexPosition+1),1) = intTempResultsHold 'Move the Number of Matches for the result from the teporary holding variable into the next array position sarySearchResults((intIndexPosition+1),2) = intTempNumMatchesHold End If Next Next End Sub'Function to read in the files meta tagsPrivate Function GetFileMetaTag(ByRef strStartValue, ByRef strEndValue, ByVal strFileContents) 'Dimension Variables Dim intStartPositionInFile 'Holds the start position in the file Dim intEndPositionInFile 'Holds the end position in the file 'Get the start position in the file of the meta tag intStartPositionInFile = InStr(1, LCase(strFileContents), strStartValue, 1) 'If no description or keywords are found then you may be using http-equiv= instead of name= in your meta tags If intStartPositionInFile = 0 And InStr(strStartValue, "name=") Then 'Swap name= for http-equiv= strStartValue = Replace(strStartValue, "name=", "http-equiv=") 'Check again for keywords or description intStartPositionInFile = InStr(1, LCase(strFileContents), strStartValue, 1) End If 'If there is a description then the position in file will be over 0 If NOT intStartPositionInFile = 0 Then 'Get the end position of the HTML meta tag intStartPositionInFile = intStartPositionInFile + Len(strStartValue) 'Get the position in file of the closing tag for the meta tag intEndPositionInFile = InStr(intStartPositionInFile, LCase(strFileContents), strEndValue, 1) 'Read in the meta tag from the file for the function to return GetFileMetaTag = Trim(Mid(strFileContents, intStartPositionInFile, (intEndPositionInFile - intStartPositionInFile))) 'If the is no meta tag then the GetFileMetaTag function returns a null value Else GetFileMetaTag = "" End IfEnd Function%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pessoal, Eu tenho aquele código acima da busca e quero tirar o acento para fazer a busca:Por exemplo: Se o cara digita um nome com acento eu quero que tire o acento para a busca, eu tenho a função mas não sei implementar. Alguém aí sabe me dizer como eu posso fazer isso?Abaixo segue a função:<%Function RemoveAcentuacao(Palavra)Dim IDim LCA(47)Dim LSA(47)LCA(0) = "ç"LCA(1) = "À"LCA(2) = "Á"LCA(3) = "Â"LCA(4) = "Ã"LCA(5) = "Ä"LCA(6) = "Å"LCA(7) = "à"LCA(8) = "á"LCA(9) = "â"LCA(10) = "ã"LCA(11) = "ä"LCA(12) = "å"LCA(13) = "È"LCA(14) = "É"LCA(15) = "Ê"LCA(16) = "Ë"LCA(17) = "è"LCA(18) = "é"LCA(19) = "ê"LCA(20) = "ë"LCA(21) = "Ò"LCA(22) = "Ó"LCA(23) = "Ô"LCA(24) = "Õ"LCA(25) = "Ö"LCA(26) = "ò"LCA(27) = "ó"LCA(28) = "ô"LCA(29) = "õ"LCA(30) = "ö"LCA(31) = "Ù"LCA(32) = "Ú"LCA(33) = "Û"LCA(34) = "Ü"LCA(35) = "ù"LCA(36) = "ú"LCA(37) = "û"LCA(38) = "ü"LCA(39) = "Ì"LCA(40) = "Í"LCA(41) = "Î"LCA(42) = "Ï"LCA(43) = "ì"LCA(44) = "í"LCA(45) = "î"LCA(46) = "ï"LCA(47) = "Ç"LSA(0) = "c"LSA(1) = "A"LSA(2) = "A"LSA(3) = "A"LSA(4) = "A"LSA(5) = "A"LSA(6) = "A"LSA(7) = "a"LSA(8) = "a"LSA(9) = "a"LSA(10) = "a"LSA(11) = "a"LSA(12) = "a"LSA(13) = "E"LSA(14) = "E"LSA(15) = "E"LSA(16) = "E"LSA(17) = "e"LSA(18) = "e"LSA(19) = "e"LSA(20) = "e"LSA(21) = "O"LSA(22) = "O"LSA(23) = "O"LSA(24) = "O"LSA(25) = "O"LSA(26) = "o"LSA(27) = "o"LSA(28) = "o"LSA(29) = "o"LSA(30) = "o"LSA(31) = "U"LSA(32) = "U"LSA(33) = "U"LSA(34) = "U"LSA(35) = "u"LSA(36) = "u"LSA(37) = "u"LSA(38) = "u"LSA(39) = "I"LSA(40) = "I"LSA(41) = "I"LSA(42) = "I"LSA(43) = "i"LSA(44) = "i"LSA(45) = "i"LSA(46) = "i"LSA(47) = "C"For i= 0 to UBound(LCA)Resultado = Replace(Palavra,LCA(i),LSA(i))If Palavra <> Resultado ThenPalavra = ""Palavra = ResultadoEnd IFNextRemoveAcentuacao = ResultadoEnd FunctionstrFrase = "Exemplo: Informação Tributário Móveis Razão Chão. Tudo que eu escrever aqui e tiver acento, serão retirados. independente do tamanho da string. Mas lembre-se, somente acentos serão retirados."strPalavra = RemoveAcentuacao(strFrase)Response.Write "Resultado: " & strPalavra%>Se souber como, posta ae!Valeu!Fael

Compartilhar este post


Link para o post
Compartilhar em outros sites

no esquema acima voce deve definir palavra="request("nome")"

 

abaixo segue uma boa tambem

Na qual str=sua querystring

<%function preparaPalavra(str)preparaPalavra = replace(str,"a","[a,á,à,ã,â,ä]")preparaPalavra = replace(preparaPalavra,"e","[e,é,è,ê,ë]")preparaPalavra = replace(preparaPalavra,"i","[i,í,ì,î,ï]")preparaPalavra = replace(preparaPalavra,"o","[o,ó,ò,õ,ô,ö]")preparaPalavra = replace(preparaPalavra,"u","[u,ú,ù,û,ü]")preparaPalavra = preparaPalavraend function' E o seu sql ficaria mais ou menos assim:sql = "select * from tabela where campo like '%" & preparaPalavra(palavraprocurada) & "%'"%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

no esquema acima voce deve definir palavra="request("nome")"abaixo segue uma boa tambemNa qual str=sua querystring

<%function preparaPalavra(str)preparaPalavra = replace(str,"a","[a,á,à,ã,â,ä]")preparaPalavra = replace(preparaPalavra,"e","[e,é,è,ê,ë]")preparaPalavra = replace(preparaPalavra,"i","[i,í,ì,î,ï]")preparaPalavra = replace(preparaPalavra,"o","[o,ó,ò,õ,ô,ö]")preparaPalavra = replace(preparaPalavra,"u","[u,ú,ù,û,ü]")preparaPalavra = preparaPalavraend function' E o seu sql ficaria mais ou menos assim:sql = "select * from tabela where campo like '%" & preparaPalavra(palavraprocurada) & "%'"%>
já tentei usar este script mas não dá certo....Estou postando um que peguei de um site, que dá certo.
'############# TIRA ACENTOS ######################Function TiraAcento(Palavra)CAcento = "àáâãäèéêëìíîïòóôõöùúûüÀÁÂÃÄÈÉÊËÌÍÎÒÓÔÕÖÙÚÛÜçÇñÑ"SAcento = "aaaaaeeeeiiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN"Texto = ""if Palavra <> "" thenFor X = 1 to Len(Palavra)Letra = mid(Palavra,X,1)Pos_Acento = inStr(CAcento,Letra)if Pos_Acento > 0 thenLetra = mid(SAcento,Pos_Acento,1)end ifTexto = Texto & LetranextTiraAcento = Textoend ifend function'############# FIM ACENTOS ######################busca = TiraAcento(busca)

Compartilhar este post


Link para o post
Compartilhar em outros sites

Quanto a essa função eu tenho essa que eu coloquei, e mais uma outra que a seguinte, mas o problema mesmo é que eu não sei implementar uma função, sou novo em asp, vim do VB:Function TiraAcento(Palavra)CAcento = "àáâãäèéêëìíîïòóôõöùúûüÀÁÂÃÄÈÉÊËÌÍÎÒÓÔÕÖÙÚÛÜçÇñÑ"SAcento = "aaaaaeeeeiiiiooooouuuuAAAAAEEEEIIIOOOOOUUUUcCnN"Texto = ""if Palavra <> "" thenFor X = 1 to Len(Palavra)Letra = mid(Palavra,X,1)Pos_Acento = inStr(CAcento,Letra)if Pos_Acento > 0 thenLetra = mid(SAcento,Pos_Acento,1)end ifTexto = Texto & LetranextTiraAcento = Textoend ifend functionFunction TrocaAcento(Palavra)CAcento = "àáâãäèéêëìíîïòóôõöùúûüÀÁÂÃÄÈÉÊËÌÍÎÒÓÔÕÖÙÚÛÜçÇñÑ"Texto = ""if Palavra <> "" thenFor X = 1 to Len(Palavra)Letra = mid(Palavra,X,1)Pos_Acento = inStr(CAcento,Letra)if Pos_Acento > 0 thenLetra = "_"end ifTexto = Texto & LetranextTrocaAcento = Textoend ifend functionPô ajuda ae gurizada.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.