Forum Moderators: coopster

Message Too Old, No Replies

Parsing XML tags

How to parse XML tags coming from a CC processor

         

Mitch888

3:25 am on Sep 6, 2003 (gmt 0)

10+ Year Member



Hi,
I want to parse an xml code that comes from a credit card processor in the following format:

On success:
<success>
<transaction>39811</transaction>
</success>

On failure:
<failure>
<error>
<code>10</code>
<message>Payment Failed</message>
</error>
</failure>

I can use parse the “39811” or “10” and “Payment Failed” by loading them into array and the value of the array
$variable[0] = 10;
$variable[1] = Payment Failed;

but how can I see or parse <failure> or </success>? I need whats between the tags as the processor does not always send the code and message. Any ideas are welcome

thank you
M

lorax

3:02 pm on Sep 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Most of the CC processors I know offer plugin modules in a variety of code languages such that all you need to do is to modify them to suit your needs. Check with your processor.

Baring that, do a search on your favoritie SE using the processors name and the keywords PHP XML.

Or you can start at the very beginning with these [google.com].

vincevincevince

11:02 pm on Sep 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if (preg_match("/success/i".$string)) $success=1;
else $success=0;

echo "Success = $success";

Mitch888

12:19 am on Sep 7, 2003 (gmt 0)

10+ Year Member



I get an error saying "Wrong parameter count for preg_match()"

any ideas?

Q: what is the "i" stand for?

thank you

Mitch888

2:43 am on Sep 7, 2003 (gmt 0)

10+ Year Member



i got it to work by using:

if (preg_match("/\bsuccess\b/i","$string")){
$success=1;
}elseif (preg_match("/\bfailure\b/i","$string")){
$success=0;
}

I now know the syntax for it. Thank you for showing me the light :)

vincevincevince

8:23 am on Sep 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



my mistake, i put a . instead of a , in my code - i apologise. your solution looks great - the "i" at the end means case insensitive - if you're certain it will always be success and never Success or SUCCESS then you may leave it out.