could you explain this cfscript please?

been searching on this site for some info on using CFHTTP, found this code (below) which pulls links, works greate.

could any one explain the bits in the cfscript tag line by line? it seems to do so much in so little code!!!

oany please is in the in array dump it shows the links and the link description, but i dont see where this is in the script.

<cfscript>
function parseURLs(obj)
{
   arr=arraynew(2);set=structnew();
   set.pos=arraynew(1);set.pos[1] = 0;
   while(true){
      set=refindnocase("<a[^>]+href=[""']([^""']*)[""'][^>]*>([^<]*)</a>",obj,set.pos[arraylen(set.pos)]+1,true);
      if(arraylen(set.len) lt 3) break;
           arr[arraylen(arr)+1][1]=mid(obj,set.pos[2],set.len[2]);
           arr[arraylen(arr)][2]=mid(obj,set.pos[3],set.len[3]);
    }
   return arr;
}
</cfscript>

<cfhttp method='get' url='http://google.com'></cfhttp>
<cfset NewArray = parseURLs(cfhttp.FileContent)>
<cfdump var="#NewArray#">  

thanks in advance :)
LVL 12
pigmentartsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mkishlineCommented:
<cfscript>
function parseURLs(obj)
{
      <!--- Initialize variables --->
      arr=arraynew(2);set=structnew();
      <!--- Create a one-dimensional array and name it "pos" --->
      set.pos=arraynew(1);
      <!--- Set the first value of the "pos" or position array to 0 --->
      set.pos[1] = 0;
      <!--- Loop --->
      while(true){
            <!--- search for a link (<a href...) tag in the html (passed in as obj to the function) starting at the position+1 specified in the last element of the set.pos array --->
            set=refindnocase("<a[^>]+href=[""']([^""']*)[""'][^>]*>([^<]*)</a>",obj,set.pos[arraylen(set.pos)]+1,true);
            <!--- if it did not find a valid link then end the loop --->
            if(arraylen(set.len) lt 3) break;
            
            <!--- if it did find a valid link --->
            arr[arraylen(arr)+1][1]=mid(obj,set.pos[2],set.len[2]); <!--- add the value of the href attributes --->
            arr[arraylen(arr)][2]=mid(obj,set.pos[3],set.len[3]); <!--- add the string between the starting and ending <a> tags --->
      }
      <!--- Return the links from the page --->
      return arr;
}
</cfscript>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pigmentartsAuthor Commented:
thanks for taking the time to explain this script to me, will review and play around with it. can i just ask with it been a one-dimensional array how come it holds 2 values for each position, or am i gettting this all wrong?
0
mkishlineCommented:
The set.pos variable is a one-dimensional array, but the two values that you're looking at are being stored in the two dimensional arr variable. The set structure is never returned and really serves no other real purpose than to hold the returned values from the REFindNoCase function.
0
pigmentartsAuthor Commented:
o i see, assumed it was a two dimensional array just got set.pos confused with arr. thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.