Jump to content

darkgr33n

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

darkgr33n's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, although not used directly, it did get me looking further, and I've come up with the following, although still seems quite long-winded. Perhaps there's no shorter way. I wish the SOAP return would add a sequential suffix to the tag names, but I don't have control over that $foo = array ( (object) array("Label" => "Street", "Line" => "Stanley Road"), (object) array("Label" => "Town", "Line" => "Manchester"), (object) array("Label" => "Number of Rules", "Line" => "2"), (object) array("Label" => "Rule", "Line" => "X014"), (object) array("Label" => "Rule Text", "Line" => "Rule text for X014"), (object) array("Label" => "Rule", "Line" => "X015"), (object) array("Label" => "Rule Text", "Line" => "Rule text for X015"), ); function objectToArray( $object ) { if( !is_object( $object ) && !is_array( $object ) ) { return $object; } if( is_object( $object ) ) { $object = get_object_vars( $object ); } return array_map( 'objectToArray', $object ); } // cast the object $array = (array) $foo; // convert array to object $array = (array) objectToArray($foo); /* which gives: Array ( [0] => Array ( [Label] => Street [Line] => Stanley Road ) [1] => Array ( [Label] => Town [Line] => Manchester ) [2] => Array ( [Label] => Number of Rules [Line] => 2 ) [3] => Array ( [Label] => Rule [Line] => X014 ) [4] => Array ( [Label] => Rule Text [Line] => Rule text for X014 ) [5] => Array ( [Label] => Rule [Line] => X015 ) [6] => Array ( [Label] => Rule Text [Line] => Rule text for X015 ) ) */ $suffix = 0; $array_count = count($array)-1; for ($i=0;$i<=$array_count ;$i++) { if ($array[$i]['Label'] != 'Rule' AND $array[$i]['Label'] != 'Rule Text') { $_SESSION[$array[$i]['Label']] = $array[$i]['Line']; } else { switch ($array[$i]['Label']) { case 'Rule': $suffix ++; $_SESSION[$array[$i]['Label'].$suffix] = $array[$i]['Line']; break; case 'Rule Text': $_SESSION[$array[$i]['Label'].$suffix] = $array[$i]['Line']; break; } } } var_dump($_SESSION); /* prints out: array(7) { ["Street"]=> string(12) "Stanley Road" ["Town"]=> string(10) "Manchester" ["Number of Rules"]=> string(1) "2" ["Rule1"]=> string(4) "X014" ["Rule Text1"]=> string(18) "Rule text for X014" ["Rule2"]=> string(4) "X015" ["Rule Text2"]=> string(18) "Rule text for X015" }
  2. ok, i've got something now, although still not too happy about two foreach loops for one iteration. foreach($foo as $bar) { if ($bar->Label != 'Rule' AND $bar->Label != 'Rule Text') { $_SESSION[$bar->Label] = $bar->Line; } else { switch ($bar->Label) { case 'Rule': $suffix ++; $rules[$bar->Label.$suffix] = $bar->Line; break; case 'Rule Text': $rules[$bar->Label.$suffix] = $bar->Line; break; } } } foreach ($rules as $key => $value) { $_SESSION[$key] = $value; } which gives the following: var_dump ($_SESSION); array(7) { ["Street"]=> string(12) "Stanley Road" ["Town"]=> string(10) "Manchester" ["Number of Rules"]=> string(1) "2" ["Rule1"]=> string(4) "X014" ["Rule Text1"]=> string(18) "Rule text for X014" ["Rule2"]=> string(4) "X015" ["Rule Text2"]=> string(18) "Rule text for X015" } which is pretty much what I was after, but open to any cleaner suggestions
  3. Ok, I've got it down a little, and am using arrays $foo = array ( (object) array("Label" => "Street", "Line" => "Stanley Road"), (object) array("Label" => "Town", "Line" => "Manchester"), (object) array("Label" => "Number of Rules", "Line" => "2"), (object) array("Label" => "Rule", "Line" => "X014"), (object) array("Label" => "Rule Text", "Line" => "Rule text for X014"), (object) array("Label" => "Rule", "Line" => "X015"), (object) array("Label" => "Rule Text", "Line" => "Rule text for X015")); $suffix = 0; $rules = array(); foreach($foo as $bar) { if ($bar->Label == 'Rule') { $suffix ++; $rules[] = array($bar->Label.$suffix => $bar->Line); } elseif ($bar->Label == 'Rule Text') { $rules[] = array($bar->Label.$suffix => $bar->Line); } else { echo ("{$bar->Label} : {$bar->Line}<br>"); } } print_r ($rules); which returns: Street : Stanley Road Town : Manchester Number of Rules : 2 Array ( [0] => Array ( [Rule1] => X014 ) [1] => Array ( [Rule Text1] => Rule text for X014 ) [2] => Array ( [Rule2] => X015 ) [3] => Array ( [Rule Text2] => Rule text for X015 ) ) which I think I can work with. The SOAP Response is always going to be a Rule followed by a Rule Text, so I should be safe ... I think ...
  4. lol, thanks for the tip, i like WIN; being self-taught I've missed some of those fundamental pearls of wisdom - i shall carry it with me always
  5. Thanks for that. I've gone down a similar road, spurred on by your first post: $rule_suffix = 0; $text_suffix = 0; foreach($foo as $bar) { if ($bar->Label == 'Rule') { $rule_suffix ++; echo ("RULE" . $rule_suffix . " : " . $bar->Line ."<br>"); } elseif ($bar->Label == 'Rule Text') { $text_suffix ++; echo ("RULE TEXT" . $text_suffix . " : " . $bar->Line ."<br>"); } else { echo ("{$bar->Label} : {$bar->Line}<br>"); } } But you're right, not sure it is the best way to go, but it works at least, so I am further on than I was. As an overview, I'm receiving a SOAP Reponse, in the format of the $foo object, and just need to parse the object, pull out the variables into Session variables, and then write to a database; Obviously if we didn't have elements of the same name returned, it would be a lot less convoluted, but unfortunately, they're the requirements we're working to. Thanks again for helping me out, I appreciate that. Also encouraged that I came up with something similar, although not as robust as yours.
  6. Yes, sort of! But, rather than echoing them out, I need to set a session variable named from the Label, which is why I tried putting them in an array, and when I get to the Rule session variable, I can add a number suffix. Sorry, maybe my initial post wasn't that clear. I really want to achieve being able to set the sessions like this: $_SESSION['Street'] = "Stanley road"; $_SESSION['Town'] = "Manchester"; $_SESSION['Rule1'] = "X014"; $_SESSION['RuleText1'] = "Rule text for X014"; $_SESSION['Rule2'] = "X015"; $_SESSION['RuleText2'] = "Rule text for X015"; so, when I come across a Rule or Rule Text Label, I need to add a count suffix to the name, so Rule + 1 Rule + 2 etc Does that make more sense ? Sorry. I've tried a few things, but it starts to get really convoluted, and I'm sure there must be an easier way! Cheers
  7. Hi I've got a StdClass Object that I need to parse. I can parse specific elements, but not sure how to parse when there is more than one element with the same name. example: $foo = array ( (object) array("Label" => "Street", "Line" => "Stanley Road"), (object) array("Label" => "Town", "Line" => "Manchester"), (object) array("Label" => "Number of Rules", "Line" => "2"), (object) array("Label" => "Rule", "Line" => "X014"), (object) array("Label" => "Rule Text", "Line" => "Rule text for X014"), (object) array("Label" => "Rule", "Line" => "X015"), (object) array("Label" => "Rule Text", "Line" => "Rule text for X015") ); /* this is what $foo contains with print_r Array ( [0] => stdClass Object ( [Label] => Street [Line] => Stanley Road ) [1] => stdClass Object ( [Label] => Town [Line] => Manchester ) [2] => stdClass Object ( [Label] => Number of Rules [Line] => 2 ) [3] => stdClass Object ( [Label] => Rule [Line] => X014 ) [4] => stdClass Object ( [Label] => Rule Text [Line] => Rule text for X014 ) [5] => stdClass Object ( [Label] => Rule [Line] => X015 ) [6] => stdClass Object ( [Label] => Rule Text [Line] => Rule text for X015 ) ) */ foreach($foo as $foo_data) { $foo_list [$foo_data->Label] = $foo_data->Line; } echo ($foo_list["Street"] . "<br>"); echo ($foo_list["Town"] . "<br>"); echo ($foo_list["Number of Rules"] . "<br>"); echo ($foo_list["Rule"] . "<br>"); echo ($foo_list["Rule Text"] . "<br>"); echo ($foo_list["Rule"] . "<br>"); echo ($foo_list["Rule Text"] . "<br>"); /* this is what is written with the echo's above - two sets of X015 Stanley Road Manchester 2 X015 Rule text for X015 X015 Rule text for X015 */ There is a "Number of Rules" element which will tell me how many Rule elements I'm expecting. This could be anything between 0 and 10 rule/rule text element pairs, the example above having 2. Any ideas how I would parse the entire array correctly [i'm going to be putting them into separate variables to use in a database, just using echo in the example. I need to see: Stanley Road Manchester 2 X014 Rule text for X014 X015 Rule text for X015 Thanks
  8. Does anyone know how to build a SOAP request using non-wsdl soap client ? It looks like it may achieve what I'm after, but I'm not sure what to put in location or uri It works something like: $client = new SoapClient(null, array('location' => "http://localhost/soap.php", 'uri' => "http://test-uri/", 'style' => SOAP_DOCUMENT, 'use' => SOAP_LITERAL)); And then I think you can add XML in the form of a variable. Anyone have any experience sending custom SOAP Requests like this ?? Thanks
  9. I'd like to change it but I can't as it's automatically created from the soapClient call, I seem to have no control over it. I wish I did. I'd like to say URI = "qas" or something, but I've searched for what seems like days, and can see no way of doing it. I've come across a few posts that call this a PHP bug, but I'm not sure. I wonder if the WSDL file is at fault ? I have no idea how these things work yet, but if it helps, here are the first few lines of the WSDL file in question: <?xml version="1.0" encoding="utf-8" ?> - <definitions name="QAS" targetNamespace="http://www.qas.com/web-2005-10" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:qas="http://www.qas.com/web-2005-10"> - <types> - <xs:schema elementFormDefault="qualified" targetNamespace="http://www.qas.com/web-2005-10" xmlns="http://www.w3.org/2001/XMLSchema">
  10. Hi All. I'm struggling with my SOAP request, and am really at a dead-end. I am not in control of the wsdl file I am referencing, just trying to format my request correctly. I am using the same wsdl file for other requests, which all work, but this one has me stumped. The reason is, I have been told I need to amend the namespace on the Request, but I have no idea how to do that, as I don't explicitly set them anywhere. Can I amend the namespace ? Here's how I make my request: $authenticate = array( 'Country' => 'GBR', 'Engine' => array ('_' => 'Authenticate', 'Flatten' => true, 'PromptSet' => 'Default'), 'Layout' => '< Default >', 'SearchSpec' => array( array('_' => 'Yes', 'Key' => 'CTRL_SEARCHCONSENT'), array('_' => 'MR', 'Key' => 'NAME_TITLE'), array('_' => 'Zuzu', 'Key' => 'NAME_FORENAME'), array('_' => '', 'Key' => 'NAME_INITIALS'), array('_' => 'Zuzu', 'Key' => 'NAME_SURNAME'), array('_' => '12/12/1956', 'Key' => 'NAME_DATEOFBIRTH'), array('_' => 'M', 'Key' => 'NAME_SEX'), array('_' => '', 'Key' => 'ADDR_FLAT'), array('_' => '', 'Key' => 'ADDR_HOUSENAME'), array('_' => '27', 'Key' => 'ADDR_HOUSENUMBER'), array('_' => 'Manor Road', 'Key' => 'ADDR_STREET'), array('_' => 'Alresford', 'Key' => 'ADDR_DISTRICT'), array('_' => 'Zuzuchester', 'Key' => 'ADDR_TOWN'), array('_' => '', 'Key' => 'ADDR_COUNTY'), array('_' => 'CO4 4LT', 'Key' => 'ADDR_POSTCODE') ) ); $response_doAuthenticate = $client->DoSearch($authenticate); and this is what I get when I grab getLastRequest: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.qas.com/web-2005-10"> <SOAP-ENV:Body> <ns1:QASearch> <ns1:Country>GBR</ns1:Country> <ns1:Engine Flatten="true" PromptSet="Default">Authenticate</ns1:Engine> <ns1:Layout><Default></ns1:Layout> <ns1:SearchSpec> <ns1:SearchTerm Key="CTRL_SEARCHCONSENT">Yes</ns1:SearchTerm> <ns1:SearchTerm Key="NAME_TITLE">MR</ns1:SearchTerm> <ns1:SearchTerm Key="NAME_FORENAME">Zuzu</ns1:SearchTerm> <ns1:SearchTerm Key="NAME_INITIALS"></ns1:SearchTerm> <ns1:SearchTerm Key="NAME_SURNAME">Zuzu</ns1:SearchTerm> <ns1:SearchTerm Key="NAME_DATEOFBIRTH">12/12/1956</ns1:SearchTerm> <ns1:SearchTerm Key="NAME_SEX">M</ns1:SearchTerm> <ns1:SearchTerm Key="ADDR_HOUSENUMBER">27</ns1:SearchTerm> <ns1:SearchTerm Key="ADDR_STREET">Manor Road</ns1:SearchTerm> <ns1:SearchTerm Key="ADDR_DISTRICT">Alresford</ns1:SearchTerm> <ns1:SearchTerm Key="ADDR_TOWN">Zuzuchester</ns1:SearchTerm> <ns1:SearchTerm Key="ADDR_POSTCODE">CO4 4LT</ns1:SearchTerm> </ns1:SearchSpec> </ns1:QASearch> </SOAP-ENV:Body> </SOAP-ENV:Envelope> BUT I have been told that the ns1: on all tags, is causing an error - but only on one line, here: <ns1:Engine Flatten="true" PromptSet="Default">Authenticate</ns1:Engine> I need this to construct is as here: <qas:Engine Flatten="true" PromptSet="Default">Authenticate</qas:Engine> or with no namespace at all: <Engine Flatten="true" PromptSet="Default">Authenticate</Engine> Is this possible ?? Perhaps I shouldn't be using soapClient. Any ideas ?! Thanks
  11. lol, I did try but couldn't work out how to do it! EDIT: FOUND IT! Thanks.
  12. UPDATE: Managed to get this working if anyone else is interested. I just needed to query the whole statement, rather than running separate queries: $sql_query = "BEGIN TRANSACTION\n"; $sql_query .= "BEGIN TRY\n"; foreach($insert_array as $value) { $sql_query .= "${$value}\n"; } $sql_query .= "COMMIT TRANSACTION\n"; $sql_query .= "END TRY\n"; $sql_query .= "BEGIN CATCH\n"; $sql_query .= "ROLLBACK TRANSACTION\n"; $sql_query .= "END CATCH\n";
  13. UPDATE: Managed to get this working if anyone else is interested. I just needed to query the whole statement, rather than running separate queries: $sql_query = "BEGIN TRANSACTION\n"; $sql_query .= "BEGIN TRY\n"; foreach($insert_array as $value) { $sql_query .= "${$value}\n"; } $sql_query .= "COMMIT TRANSACTION\n"; $sql_query .= "END TRY\n"; $sql_query .= "BEGIN CATCH\n"; $sql_query .= "ROLLBACK TRANSACTION\n"; $sql_query .= "END CATCH\n";
  14. Ah, ok, thanks. Don't think mssql has anything like that. If I actually surpress the ROLLBACK query with @mssql_query("ROLLBACK TRAN"), everything works as expected, but not sure running and hiding from the error [The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION] is the correct thing to do ?? mssql_query("BEGIN TRAN"); foreach($insert_array as $value) { $result = @mssql_query(${$value}); if(!$result) { @mssql_query("ROLLBACK TRAN"); } } @mssql_query("COMMIT TRAN"); I do remember reading something about COMMIT/ROLLBACK not working if more than one mssql_query is run as it loses its memory, but also read somewhere that was untrue. Not sure what to think. Maybe I'm better using the pseudo rollback, rather than surpress the error on the real one [even though it seems to work; it doesn't write to the DB if there's an data error, and if the data is fine, it writes ok] Way out of my depth on this one. ?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.