home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Documentation / snippets / findoneof.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  3.3 KB  |  98 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. FindOneOf Example
  7. </TITLE>
  8. </HEAD>
  9.  
  10. <BODY bgcolor=silver>
  11. <H3>FindOneOf 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="findoneof.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.  
  61. <!--- wait to have a string for searching defined --->
  62. <CFIF IsDefined("form.myString") and IsDefined("form.type")>
  63.     <!--- Now, test to see if the term was found --->
  64.     A     <CFIF form.type is "find">case-sensitive
  65.             <CFSET tag="find">
  66.         <CFELSEIF form.type is "findNoCase">case-insensitive 
  67.             <CFSET tag="findNoCase">
  68.         <CFELSEIF form.type is "findOneOf">find the first instance of any character
  69.             <CFSET tag="findOneOf">
  70.         </CFIF> test for your string "<CFOUTPUT>#form.MyString#</CFOUTPUT>"
  71.     in the url: "<CFOUTPUT>#urlAddress#</CFOUTPUT>"
  72.  
  73. <!--- depending upon the action desired, perform
  74. different function --->
  75. <CFSWITCH EXPRESSION="#tag#">
  76.     <CFCASE value="find">
  77.         <CFSET TheAction = Find("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  78.     </CFCASE>
  79.     <CFCASE value="findNoCase">
  80.         <CFSET TheAction = FindNoCase("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  81.     </CFCASE>    
  82.     <CFCASE value="findOneof">
  83.         <CFSET TheAction = FindOneOf("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  84.     </CFCASE>    
  85.     <CFDEFAULTCASE>
  86.         <CFSET TheAction = Find("#form.MyString#", "#CFHTTP.FileContent#", 1)>
  87.     </CFDEFAULTCASE>
  88. </CFSWITCH>
  89.     <CFIF TheAction is not 0>
  90.     <P>We found an instance of your string at index <CFOUTPUT>#theAction#</CFOUTPUT>
  91.     <CFELSE>
  92.     <P>No instance of your string was found.
  93.     </CFIF>
  94. </CFIF>
  95.  
  96. </BODY>
  97. </HTML>       
  98.