Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfhttp filecontent result manipulation

Status
Not open for further replies.

Lethal007

Programmer
Sep 8, 2007
2
AU
Hi All,

I am trying to grab results from a cfhttp post, but do not know how to manipulate the results.

This is an example of the results:

complete

.
card_number=411111xxxx1111
settlement_date=31/07/00
response_text=INVALID TRANSACTION
amount=100
status=complete
txnref=0007311428202312
bank_ref=000731000024
card_desc=VISA
response_code=12
card_expiry=01/01
MID=24
card_type=6
time=2000-07-31 14:28:20
command=purchase
result=0

How do i turn the results into variable. Ie how do grab the status as a variable with len functions etc?

If the result is failed the output will look like this:

failed

.
status=failed
result=-1

Any suggestions?

Thanks.
 
Try treating the content as nested lists. Each name/value are delimited by "=". Each name/value pair is delimited by what looks like a newline character or maybe chr(10)?


Code:
<cfsavecontent variable="fileContent">
complete

.
card_number=411111xxxx1111
settlement_date=31/07/00
response_text=INVALID TRANSACTION
amount=100
status=complete
txnref=0007311428202312
bank_ref=000731000024
card_desc=VISA
response_code=12
card_expiry=01/01
MID=24
card_type=6
time=2000-07-31 14:28:20
command=purchase
result=0
</cfsavecontent>

<cfset lineDelim = chr(13) & chr(10)>
<cfset valueDelim = "=">
<cfset valueStruct = structNew()>
<cfloop list="#fileContent#" index="line" delimiters="#lineDelim#">
	<!--- lines without a "=" will be ignored --->
	<cfif listLen(line, valueDelim) gte 2>
		<cfset valueStruct[listFirst(line, valueDelim)] = listRest(line, valueDelim) >
	</cfif>
</cfloop>

<cfoutput>
status = #valueStruct.status#<br>
result = #valueStruct.result#<hr>
</cfoutput>

<!--- show all --->
<cfdump var="#valueStruct#">
 
Thanks, that's a slick bit of code.

Works well.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top