> I am recieving a list of name value pairs being sent back from a
> cfhttp post to bank of america.
>
> The post returns the name value pairs like this:
>
> var1=sometext<br>
> var2=<br>
> var3=9999999<br>
> var4=sometext
>
> some times the variables are sent back without a value like var2
> above. The variable names are not as easy as listed above but rather
> pretty random. Can some one help me parse these values into variables
> I can use to insert into the database?
>
Assuming that you've removed any additional html or you are only
returned a list of variables similar to above:
Replace any CRLFs that are in the returned html using
replace(yourvar,chr(13)&chr(10),"","all"), so that you get your
variables returned like this :

var1=sometext<br> var2=<br> var3=9999999<br>var4=sometext

Treat the whole thing as a list with <br> as your list delimiter and
loop around it. Inside the loop treat each list item as a list again,
but with = as your list delimiter. This will give you your value pairs.
You can then do with them as you please. In the code below I've inserted
the variables and thier values into a struct called valuestruct, so that
you can access your variables and values using valuestruct.var1,
valuestruct.var2 etc.

<cfscript>
yourvar = "var1=sometext<br> var2=<br> var3=9999999<br>var4=sometext";
valuecount = listlen(yourvar,"<br>");
valuestruct = structnew();
for (i=1; i lte valuecount; i=i+1) {
    thisPair = ListGetAt(yourvar,i,"<br>");
    thisVariable = ListFirst(thisPair,"=");
    thisValue = ListLast(thisPair,"=");
    valuestruct[thisVariable] = thisValue;
}
</cfscript>

Hope this helps

Regards

Stephen
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to