答案 0 :(得分:0)
如果源是回车分隔的textarea,您可以将文本区域视为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>
答案 1 :(得分:0)
我弄明白了,看看this code on trycf.com。我将在此发布以供参考。为了解决这个问题,我开始使用条件循环。在该循环内部,我使用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>