Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

List All Images Used In Articles From A Content Management System

Posted on 2007-07-22
4
Medium Priority
?
139 Views
Last Modified: 2013-12-24
Can someone help me with what I think is probably a simple solution?  I simply want to create a list of all images used in articles from a content management system.  So I need to start with

<cfquery name="GetArticles" datasource="myDB">
Select * from myArticles
</cfquery>

Loop through them...

And produce a list like

/images/image1.jpg
/secondaryimages/image1.gif
http://www.somewhere.com/images/thisimage.jpg

I know I need a regular expression but can't seem to come up with the logic to put it all togther.

500 points for the solution
0
Comment
Question by:SiriusPhil
  • 2
4 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 19544462

How about this?    you have to exchagne the imageFile in your query with the real column name..

<cfoutput query="getArticles">
   #getArticles.imageFile#<br>
</cfoutput>


>  I know I need a regular expression but can't seem to come up with the logic to put it all togther.

I think you've left out the details of your question that may lead someone to think of a regular expression.   We don't know what data you have in your table and if  "/images/image1.jpg" is in a column of your table, you just need to display it as I've shown.  

If there is something else you're looking for, please update with more information about what it is you have and what you want..

0
 

Author Comment

by:SiriusPhil
ID: 19544486
There can be many images in each database entry.  The image tags are stored in the database field along with a ton of other HTML.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 19544624
Something like this...   (not tested)

 This should find the image tags (<img>)

 <cfset locations =  refind("<img[^>]*>", theHTML,  1,  TRUE)>

 refind (when using TRUE at the end) will return an array of positions and lengths..

 <cfloop index="i" from="1" to="#ArrayLen(locations.pos)#">
   #Mid(theHTML,  locations.pos[i],  locations.len[i])# <br>
</cfloop>
0
 
LVL 14

Accepted Solution

by:
Scott Bennett earned 2000 total points
ID: 19549798
Here is a function that will return an array of the values within the src attributes of all img tags in your string. Currently it requires that all the src attributes be enclosed in quotes ("), but it can be modified to look for single quotes as wellif needed.


<cffunction name="FindIMGs" output="true" returntype="array">

   <cfargument name="text" type="string" required="yes">
   <!--- Define local variables --->
   <cfset var results=ArrayNew(1)>
   <cfset var pos=1>
   <cfset var subex="">
   <cfset var done=false>

   <cfloop condition="not done">

      <!--- Perform search --->
      <cfset subex=reFind("<img[^>]*>", arguments.text, pos, true)>
      <!--- Anything matched? --->
      <cfif subex.len[1] is 0>
         <cfset done=true>
      <cfelse>
              <!--- find src attribute and get its value --->
               <cfset srcA=find("src",mid(text,subex.pos[1],subex.len[1]))>
             <cfset srcB=find("""",mid(text,subex.pos[1],subex.len[1]),srcA)>
             <cfset srcC=find("""",mid(text,subex.pos[1],subex.len[1]),srcB+1)>
             <cfset srcValue=mid(mid(text,subex.pos[1],subex.len[1]),srcB+1,srcC-srcB-1)>
         <!--- Got one, add to array if it's not ther already --->
             <cfif not listfind(arraytolist(results),srcValue)>
             <cfset arrayappend(results,srcValue)>
             </cfif>
         <!--- Reposition start point --->
         <cfset pos=subex.pos[1]+subex.len[1]>
      </cfif>
   </cfloop>

   <!--- and return results --->
   <cfreturn results>
</cffunction>

<cfset IMGArray = FindIMGs(MyArticleContent)>
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question