Coldfusion 搜索 HTML <textarea> 然后将所有 <img> 源 URL 添加到数组
Coldfusion Search HTML <textarea> Then Add All <img> Source URLs To Array
我需要帮助了解如何在找到第一次出现后继续循环。
@luxdvie 创建的循环很棒 ()。我正在尝试扩展该循环以查找所有图像文件名并将它们放入一个数组中。
我正在 trycf.com (link here) 对其进行测试,但有时我们的互联网过滤器会阻止该站点。
我认为完成这项工作的逻辑是找到第一次出现的图像源,将其结束设置为新步骤的开始,然后继续寻找下一次出现,直到文本区域结束.
这是我尝试使用的代码:
<cfset search_text_area = #form.overview_text#>
<cfset length_of_text_field = #Len(search_text_area)#>
<cfset image_url_header = "https://ImagesFolder/subFolder/">
<cfset image_url_closure = '"'>
<cfset image_extension_png = ".png">
<cfset image_list_array_on_submit =[]>
<cfset continue_searching_url = true>
<cfset first_pass = true>
<cfset go_thru_again = false>
<cfset counter = 0>
<cfloop condition = "continue_searching_url eq true">
<cfoutput>
<cfset counter = counter+1>
<cfif counter GTE 5>
<script>console.log('WARNING! Long loop: x ' + <cfoutput>#counter#</cfoutput>);</script>
<cfbreak>
</cfif>
<cfif starting_index_url eq 0>
<cfset continue_searching_url = false>
<cfcontinue>
</cfif>
<cfif first_pass eq true>
<cfset starting_index_url = find(image_url_header, search_text_area)>
<cfset ending_index_url = find( image_url_closure , search_text_area, starting_index_url )>
<cfset full_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset starting_index_url = #ending_index_url#>
</cfif>
<cfif go_thru_again = true>
<cfif starting_index_url NEQ length_of_text_field>
<cfset starting_index_url = find(image_url_header, search_text_area)>
<cfset ending_index_url = find( image_url_closure , search_text_area, starting_index_url )>
<cfset full_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset starting_index_url = #ending_index_url#>
<cfelse>
<cfset starting_index_url = 0>
<cfcontinue>
</cfif>
<cfset go_thru_again = false>
</cfif>
</cfoutput>
</cfloop>
如果源是一个由回车符 return 分隔的文本区域,您可以将文本区域视为一个以 chr(10) 分隔的列表:
<cfset search_text_area = #form.overview_text#>
<cfset length_of_text_field = #Len(search_text_area)#>
<cfset image_url_header = "https://ImagesFolder/subFolder/">
<cfset image_url_closure = '"'>
<cfset image_extension_png = ".png">
<cfset image_list_array_on_submit =[]>
<cfset continue_searching_url = true>
<cfset first_pass = true>
<cfset go_thru_again = false>
<cfset counter = 0>
<cfloop from="1" to="#listlen(search_text_area,chr(10))#" index="linex">
<cfset thisrow=listgetat(search_text_area,linex,chr(10))>
<cfif findnocase(image_url_header,thisrow) gt 0>
<cfif findnocase(image_url_closure,thisrow,findnocase(image_url_header,thisrow)) gt 0>
<cfset starting_index_url = findnocase(image_url_header,thisrow)>
<cfset ending_index_url = findnocase(image_url_closure,thisrow,findnocase(image_url_header,thisrow))>
<cfset full_occurrence_url = mid(search_text_area, (starting_index_url), ((ending_index_url)-starting_index_url))>
<cfset local_occurrence_url = mid(search_text_area, (starting_index_url), ((ending_index_url)-starting_index_url))>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
</cfif>
</cfif>
</cfloop>
我想通了,看看this code on trycf.com。我将post 放在这里以供参考。为了解决这个问题,我从一个条件循环开始。在该循环内,我使用 IF 语句在第一遍和后续遍之间切换。我检查某些条件以退出循环。我的代码依赖于 ColdFusion 的 find() 和 mid() 函数来定位图像标签的来源 URL。
<cfsavecontent variable="SearchText">
Two images with source set to URL:
<p><img alt="Blah, Blah, Blah" src="https://ImagesFolder/subFolder/large-colored-bullets-3-0-14248.png" style="border-image:none; border:1px solid currentColor; float:left; height:200px; margin:12px; width:200px" /></p>
<p>and one more for testing:<img alt="something here" src="https://ImagesFolder/subFolder/goldmedal.png" style="border-image:none; border:1px solid currentColor; float:left; height:200px; margin:12px; width:200px" /></p>
</cfsavecontent>
<cfset search_text_area = #SearchText#>
<cfset length_of_text_field = #Len(search_text_area)#>
<cfset image_url_header = "https://ImagesFolder/subFolder/">
<cfset image_url_closure = '"'>
<cfset image_extension_png = ".png">
<cfset image_list_array_on_submit =[]>
<cfset counter_array =[]>
<cfset continue_searching_url = true>
<cfset first_pass = true>
<cfset go_thru_again = false>
<cfset counter = 0>
<cfset next_position = -1>
<cfloop condition = "continue_searching_url eq true">
<cfoutput>
<cfset counter = counter+1>
<!---<cfif counter GTE 5>
<cfbreak>
</cfif>--->
<cfif first_pass eq true>
<cfset starting_index_url = find(image_url_header, SearchText)>
</cfif>
<cfif go_thru_again eq true>
<cfset next_position = #ending_index_url#>
</cfif>
<cfif starting_index_url eq 0>
<cfset continue_searching_url = false>
<cfcontinue>
</cfif>
<cfif first_pass eq true>
<cfset ending_index_url = find( image_url_closure , SearchText, starting_index_url )>
<cfset full_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset next_position = #ending_index_url#>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
</cfif>
<cfset ArrayAppend(counter_array, starting_index_url)>
<cfif go_thru_again = true>
<cfif starting_index_url NEQ length_of_text_field>
<cfoutput><span style="color:brown;">#counter#. #starting_index_url#, #next_position#</span><br></cfoutput>
<cfset starting_index_url = find(image_url_header, SearchText, next_position)>
<cfset ending_index_url = find( image_url_closure , SearchText, starting_index_url )>
<cfif starting_index_url eq 0>
<cfset continue_searching_url = false>
<cfcontinue>
</cfif>
<cfset full_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset next_position = #ending_index_url#>
<cfoutput><span style="color:blue;">#counter#. #starting_index_url#, #next_position#, #ending_index_url#</span><br></cfoutput>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
<cfelse>
<cfset go_thru_again = false>
<cfset starting_index_url = 0>
<cfcontinue>
</cfif>
</cfif>
</cfoutput>
我需要帮助了解如何在找到第一次出现后继续循环。
@luxdvie 创建的循环很棒 (
我认为完成这项工作的逻辑是找到第一次出现的图像源,将其结束设置为新步骤的开始,然后继续寻找下一次出现,直到文本区域结束.
这是我尝试使用的代码:
<cfset search_text_area = #form.overview_text#>
<cfset length_of_text_field = #Len(search_text_area)#>
<cfset image_url_header = "https://ImagesFolder/subFolder/">
<cfset image_url_closure = '"'>
<cfset image_extension_png = ".png">
<cfset image_list_array_on_submit =[]>
<cfset continue_searching_url = true>
<cfset first_pass = true>
<cfset go_thru_again = false>
<cfset counter = 0>
<cfloop condition = "continue_searching_url eq true">
<cfoutput>
<cfset counter = counter+1>
<cfif counter GTE 5>
<script>console.log('WARNING! Long loop: x ' + <cfoutput>#counter#</cfoutput>);</script>
<cfbreak>
</cfif>
<cfif starting_index_url eq 0>
<cfset continue_searching_url = false>
<cfcontinue>
</cfif>
<cfif first_pass eq true>
<cfset starting_index_url = find(image_url_header, search_text_area)>
<cfset ending_index_url = find( image_url_closure , search_text_area, starting_index_url )>
<cfset full_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset starting_index_url = #ending_index_url#>
</cfif>
<cfif go_thru_again = true>
<cfif starting_index_url NEQ length_of_text_field>
<cfset starting_index_url = find(image_url_header, search_text_area)>
<cfset ending_index_url = find( image_url_closure , search_text_area, starting_index_url )>
<cfset full_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#search_text_area#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset starting_index_url = #ending_index_url#>
<cfelse>
<cfset starting_index_url = 0>
<cfcontinue>
</cfif>
<cfset go_thru_again = false>
</cfif>
</cfoutput>
</cfloop>
如果源是一个由回车符 return 分隔的文本区域,您可以将文本区域视为一个以 chr(10) 分隔的列表:
<cfset search_text_area = #form.overview_text#>
<cfset length_of_text_field = #Len(search_text_area)#>
<cfset image_url_header = "https://ImagesFolder/subFolder/">
<cfset image_url_closure = '"'>
<cfset image_extension_png = ".png">
<cfset image_list_array_on_submit =[]>
<cfset continue_searching_url = true>
<cfset first_pass = true>
<cfset go_thru_again = false>
<cfset counter = 0>
<cfloop from="1" to="#listlen(search_text_area,chr(10))#" index="linex">
<cfset thisrow=listgetat(search_text_area,linex,chr(10))>
<cfif findnocase(image_url_header,thisrow) gt 0>
<cfif findnocase(image_url_closure,thisrow,findnocase(image_url_header,thisrow)) gt 0>
<cfset starting_index_url = findnocase(image_url_header,thisrow)>
<cfset ending_index_url = findnocase(image_url_closure,thisrow,findnocase(image_url_header,thisrow))>
<cfset full_occurrence_url = mid(search_text_area, (starting_index_url), ((ending_index_url)-starting_index_url))>
<cfset local_occurrence_url = mid(search_text_area, (starting_index_url), ((ending_index_url)-starting_index_url))>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
</cfif>
</cfif>
</cfloop>
我想通了,看看this code on trycf.com。我将post 放在这里以供参考。为了解决这个问题,我从一个条件循环开始。在该循环内,我使用 IF 语句在第一遍和后续遍之间切换。我检查某些条件以退出循环。我的代码依赖于 ColdFusion 的 find() 和 mid() 函数来定位图像标签的来源 URL。
<cfsavecontent variable="SearchText">
Two images with source set to URL:
<p><img alt="Blah, Blah, Blah" src="https://ImagesFolder/subFolder/large-colored-bullets-3-0-14248.png" style="border-image:none; border:1px solid currentColor; float:left; height:200px; margin:12px; width:200px" /></p>
<p>and one more for testing:<img alt="something here" src="https://ImagesFolder/subFolder/goldmedal.png" style="border-image:none; border:1px solid currentColor; float:left; height:200px; margin:12px; width:200px" /></p>
</cfsavecontent>
<cfset search_text_area = #SearchText#>
<cfset length_of_text_field = #Len(search_text_area)#>
<cfset image_url_header = "https://ImagesFolder/subFolder/">
<cfset image_url_closure = '"'>
<cfset image_extension_png = ".png">
<cfset image_list_array_on_submit =[]>
<cfset counter_array =[]>
<cfset continue_searching_url = true>
<cfset first_pass = true>
<cfset go_thru_again = false>
<cfset counter = 0>
<cfset next_position = -1>
<cfloop condition = "continue_searching_url eq true">
<cfoutput>
<cfset counter = counter+1>
<!---<cfif counter GTE 5>
<cfbreak>
</cfif>--->
<cfif first_pass eq true>
<cfset starting_index_url = find(image_url_header, SearchText)>
</cfif>
<cfif go_thru_again eq true>
<cfset next_position = #ending_index_url#>
</cfif>
<cfif starting_index_url eq 0>
<cfset continue_searching_url = false>
<cfcontinue>
</cfif>
<cfif first_pass eq true>
<cfset ending_index_url = find( image_url_closure , SearchText, starting_index_url )>
<cfset full_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset next_position = #ending_index_url#>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
</cfif>
<cfset ArrayAppend(counter_array, starting_index_url)>
<cfif go_thru_again = true>
<cfif starting_index_url NEQ length_of_text_field>
<cfoutput><span style="color:brown;">#counter#. #starting_index_url#, #next_position#</span><br></cfoutput>
<cfset starting_index_url = find(image_url_header, SearchText, next_position)>
<cfset ending_index_url = find( image_url_closure , SearchText, starting_index_url )>
<cfif starting_index_url eq 0>
<cfset continue_searching_url = false>
<cfcontinue>
</cfif>
<cfset full_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset local_occurrence_url = mid(#SearchText#, (#starting_index_url#), ((#ending_index_url#)-#starting_index_url#))>
<cfset first_pass = false>
<cfset go_thru_again = true>
<cfset next_position = #ending_index_url#>
<cfoutput><span style="color:blue;">#counter#. #starting_index_url#, #next_position#, #ending_index_url#</span><br></cfoutput>
<cfset ArrayAppend(image_list_array_on_submit, (local_occurrence_url))>
<cfelse>
<cfset go_thru_again = false>
<cfset starting_index_url = 0>
<cfcontinue>
</cfif>
</cfif>
</cfoutput>