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