Welcome to WebmasterWorld Guest from 50.16.78.128

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Parsing results

   
5:24 am on Oct 20, 2009 (gmt 0)

5+ Year Member



I have an exting script which parses an XML response for a 1 or a 0, however now the response has changed and I was wondering if anyone had any idea how I could update it.

Sucess was the xml response

<result>1</result>

the code to parse was

list($a,$b)=split("<result>",$full_arr['response'][$key],2);
list($c,$d)=split("</result>",$b,2);
if ($c==1) {$succ="SUCCESS"; $no_of_succ++;}
else $succ="FAILED";

The error was <result>0</result>

The sucessful response now is

ID: # (where # is the id of the message)

And error is Err: 601

6:54 am on Oct 20, 2009 (gmt 0)

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



How about:
if(preg_match("/<result>([0-9]+)<\/result>/",$xml_repsonse,$store_number)) {
$the_id_number=$store_number[1];
// The rest of your code here.
}

else {
echo $error="There was no number between <result> &amp; </result>";
}

3:51 pm on Oct 20, 2009 (gmt 0)

5+ Year Member



But the sucessful response does not have the word result in it. Why use the word result? thanks
9:09 pm on Oct 20, 2009 (gmt 0)

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Uh, I was going by what you posted as the successful response? What I posted matches <result>ANYNUMBER</result> I used a regular expression to do what you were doing with the code below, without pulling the code apart... (I'm really not sure if I understand your question or not.)

list($a,$b)=split("<result>",$full_arr['response'][$key],2);
list($c,$d)=split("</result>",$b,2);
if ($c==1) {$succ="SUCCESS"; $no_of_succ++;}
else $succ="FAILED";

This would match only <result>0</result> or <result>1</result>
if(preg_match("/<result>([0-1]{1})<\/result>/",$xml_repsonse,$store_number)) {
$the_id_number=$store_number[1];
// The rest of your code here.
}

else {
echo $error="There was no number between <result> &amp; </result>";
}

I just expanded it to match any number between the <result> tags.

If you need the tags stored, use something like:
preg_match("/(<result>([0-9]+)<\/result>)/",$xml_repsonse,$store_number));
if($store_number[2]!='') {
$the_id_number=$store_number[2];
echo "There was a number between <result> &amp; </result> the full string is:<br />";
echo $store_number[1];
// The rest of your code here.
}

else {
echo $error="There was no number between <result> &amp; </result>";
}

10:26 pm on Oct 20, 2009 (gmt 0)

5+ Year Member



The code I posted already worked based on parsing the text between the word "response". However the sucessful response now is

ID: # (where # is the id of the message)

and error is Err: 601

So perhaps just an updated string that searches for the begining of the string to be ID: if not error.

11:46 pm on Oct 20, 2009 (gmt 0)

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



The code I posted already worked based on parsing the text between the word "response". However the sucessful response now is

ID: # (where # is the id of the message)

I'm not sure about the error number, but it seems to me you will need to match and store the value (or at least check for a numerical match) between the response tags... What I posted does that. I'll leave it to you or someone else who has a better idea than I do.

Maybe intval() will help you out, because it seems you are checking for 1 or 0 and not 'any number except 0' as you will need to do (IMO) to ensure an accurate match... I'll leave it to you and others from here.

Sorry I couldn't be of more help.

11:58 pm on Oct 20, 2009 (gmt 0)

5+ Year Member



I do not need to match the response tags. that was the old sucess response... now I just get ID:

I do not care abotu the error number

Basically look for begining string ID: = sucess if it is something else then error

12:09 am on Oct 21, 2009 (gmt 0)

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



I have no clue what you're asking for if you're posting old code, rather than what you're actually looking for a response in... How do you get the ID? Is it just the number? No one can really answer when they don't know what you're getting now and need to check for a match of some type.

Like I said, I'm clueless as to what you're looking for and apparently all you've posted is the old code without posting what you're actually searching through to find the ID now. Are you even searching anything?

Do you mean you get ID: NUMBER?

Then just modify my regular expression:
if(preg_match("/^ID:\s?[0-9]+$/"),$what_ever_variable_you_are_using) {
echo "There's a number here.";
}

12:13 am on Oct 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you considered using simplexml and actually parsing the result?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month