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