home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / find.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  3.3 KB  |  97 lines

  1. <!--- This example uses find, findnocase, and findoneof
  2.  to see if a substring exists in a web page --->
  3. <HTML>
  4. <HEAD>
  5. <TITLE>
  6. Find Example
  7. </TITLE>
  8. </HEAD>
  9.  
  10. <BODY bgcolor=silver>
  11. <H3>Find Example</H3>
  12.  
  13. <P>This example uses find, findnocase and findone of to see 
  14. if a substring exists in a particular web page.
  15.  
  16. <FORM ACTION="find.cfm" METHOD="POST">
  17. Try entering a URL for the tag to return:
  18. <BR><INPUT TYPE="Text" size=25 NAME="urladdress" VALUE="http://www.allaire.com">
  19. <P>And a substring to search for:
  20. <BR><INPUT TYPE="Text" size=25 NAME="myString" VALUE="Allaire">
  21. <P>Pick a search type:
  22.     <SELECT NAME="type">
  23.         <OPTION VALUE="find" SELECTED>Case-Sensitive
  24.         <OPTION VALUE="findNoCase">Case-Insensitive
  25.         <OPTION VALUE="findOneOf">Find first instance
  26.     </SELECT>
  27. <INPUT TYPE="Submit" NAME="" VALUE="get page">
  28. </FORM>
  29.  
  30. <!--- sets a default value for a url to retrieve --->
  31. <CFPARAM name="urladdress" default="http://localhost/cfdocs/index.htm">
  32. <!--- if we have passed a url address in the form, we
  33. want to display the passed address --->
  34. <CFIF IsDefined("form.urladdress") is True>
  35. <!--- do simple error check to avoid crashing the
  36. tag --->
  37.     <CFIF #Trim("#Form.urladdress#")# is "" or #Trim("#Form.urladdress#")# is "http://">
  38. <!--- if error condition tripped, set alternative --->
  39.         <CFSET urlAddress ="http://localhost/cfdocs/index.htm">
  40.         <H4>because you entered no url or an empty string, the tag
  41.         will return the following address: http://localhost/cfdocs/index.htm</H4>
  42.     <CFELSE>
  43. <!--- otherwise use address passed from form --->
  44.         <CFSET urlAddress = "#form.urladdress#">
  45.     </CFIF>
  46. <!--- now use the CFHTTP tag to get the file content
  47. represented by urladdress --->    
  48.         <CFHTTP URL="#urladdress#"
  49.             METHOD="GET"
  50.             RESOLVEURL=YES>
  51.         </CFHTTP>
  52. <CFELSE>
  53. <!--- the first time through, retrieve a URL that we know
  54. exists --->
  55. <CFHTTP URL="http://localhost/cfdocs/index.htm"
  56.     METHOD="GET"
  57.     RESOLVEURL=YES>
  58. </CFHTTP>
  59. </CFIF>
  60. <!--- wait to have a string for searching defined --->
  61. <CFIF IsDefined("form.myString") and IsDefined("form.type")>
  62.     <!--- Now, test to see if the term was found --->
  63.     A     <CFIF form.type is "find">case-sensitive
  64.             <CFSET tag="find">
  65.         <CFELSEIF form.type is "findNoCase">case-insensitive 
  66.             <CFSET tag="findNoCase">
  67.         <CFELSEIF form.type is "findOneOf">find the first instance of any character
  68.             <CFSET tag="findOneOf">
  69.         </CFIF> test for your string "<CFOUTPUT>#form.MyString#</CFOUTPUT>"
  70.     in the url: "<CFOUTPUT>#urlAddress#</CFOUTPUT>"
  71.  
  72. <!--- depending upon the action desired, perform
  73. different function --->
  74. <CFSWITCH EXPRESSION="#tag#">
  75.     <CFCASE value="find">
  76.         <CFSET TheAction = Find("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  77.     </CFCASE>
  78.     <CFCASE value="findNoCase">
  79.         <CFSET TheAction = FindNoCase("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  80.     </CFCASE>    
  81.     <CFCASE value="findOneof">
  82.         <CFSET TheAction = FindOneOf("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  83.     </CFCASE>    
  84.     <CFDEFAULTCASE>
  85.         <CFSET TheAction = Find("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  86.     </CFDEFAULTCASE>
  87. </CFSWITCH>
  88.     <CFIF TheAction is not 0>
  89.     <P>We found an instance of your string at index <CFOUTPUT>#theAction#</CFOUTPUT>
  90.     <CFELSE>
  91.     <P>No instance of your string was found.
  92.     </CFIF>
  93. </CFIF>
  94.  
  95. </BODY>
  96. </HTML>       
  97.