0

I've made a PHP SOAP request, the request returns a complete dump of the contents, How do I format it ? Never used xml or PHP,SOAP before this ? The code:

<?php  
$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');
$result = $client->getVehicleDetails('redacted','redacted'); 
echo('<p>'.$result.'</p>');
?>

Returns:

5002386176AHTHA3CD503427515BPSSZN1GD058155439845.00WHITE2019TOYOTAHILUX 2.8 GD-6 RAIDER 4X4 A/T P/U D/C60039521Full Service History with agentsSigns of cosmetic workhttp://www.autobid.co.za/images/image_5002386176.jpghttp://www.autobid.co.za/images/image_5002386176_1.jpghttp://www.autobid.co.za/images/image_5002386176_2.jpghttp://www.autobid.co.za/images/image_5002386176_3.jpghttp://www.autobid.co.za/images/image_5002386176_4.jpg541000.00541000.00Black leatherSpare Key: Yes,Bin Liner: Yes,Leather Seats: Yes,Tonneau Cover: Yes,Rollbar: Yes,Towbar: Yes,Bullbar: Yes,Other Extras/Comments: WHEEL ARCHES SIDE VISORS,5002371142AHTBB0JE400024849NX423391ZRV93623779342.00WHITE2019TOYOTACOROLLA 1.6 PRESTIGE CVT60027544Full Service History with agentsSigns of cosmetic workhttp://www.autobid.co.za/images/image_5002371142.jpghttp://www.autobid.co.za/images/image_5002371142_1.jpghttp://www.autobid.co.za/images/image_5002371142_2.jpghttp://www.autobid.co.za/images/image_5002371142_3.jpghttp://www.autobid.co.za/images/image_5002371142_4.jpg220000.00220000.00BlackSpare Key: Yes,5002366129AAVZZZ6SZBU019983ND606937CLP043956108334.00SILVER2011VOLKSWAGENPOLO VIVO 1.4 TRENDLINE TIP 5DR64020120Full Service History agent & non-agentSigns of cosmetic workhttp://www.autobid.co.za/images/image_5002366129.jpghttp://www.autobid.co.za/images/image_5002366129_1.jpghttp://www.autobid.co.za/images/image_5002366129_2.jpghttp://www.autobid.co.za/images/image_5002366129_3.jpghttp://www.autobid.co.za/images/image_5002366129_4.jpg75000.0075000.00GreySpare Key: Yes,5002364072JTMZ43FV70D511939ND842882M20AV1456899963.00WHITE2020TOYOTARAV4 2.0 GX CVT60077613Not due for service yetSigns of cosmetic workhttp://www.autobid.co.za/images/image_5002364072.jpghttp://www.autobid.co.za/images/image_5002364072_1.jpghttp://www.autobid.co.za/images/image_5002364072_2.jpghttp://www.autobid.co.za/images/image_5002364072_3.jpghttp://www.autobid.co.za/images/image_5002364072_4.jpg416000.00416000.00Black5002357702AHTLB52E003096386ND1467581ZRV044055127338.00WHITE2015TOYOTACOROLLA QUEST 1.660010250Full Service History with agentsSigns of cosmetic

I need it in a better-formatted method rather than just a dump like that, never used SOAP nor PHP before this so got it to this point but want a better representation of the data now, please assist if you can, much appreciated!

Anton Krug
  • 1,555
  • 2
  • 19
  • 32
Foholoc
  • 23
  • 3
  • What you probably have there is XML, but after wrapping it in a

    and viewing it in your browser, that is lost. If you view the page source (not inspector), you'll probably see XML. Likewise if you use `echo '

    ' . $result '
    ';` I would expect you see more sensible formatting. But then you will need to parse the XML to get the information actually needed.
    – Michael Berkowski Jun 08 '21 at 12:47
  • So that turned the result to come on a single line, how would one parse the XML ? Can see the tags in page source. Thanks for your time – Foholoc Jun 08 '21 at 13:02

1 Answers1

0
<?php  

$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');

$result = $client->getVehicleDetails('redacted','redacted');

var_dump(simplexml_load_string($result));

If you use var_dump you can see that it returns a string. In this case the string contains XML data which can be parsed e.g. via simplexml to receive an object. The fact that your method returns a string is also reflected in the wsdl-file:

<message name="getVehicleDetailsResponse">
    <part name="return" type="xsd:string"/>
</message> 
Chris
  • 71
  • 3
  • On this i receive an error : Warning: simplexml_load_string(): Entity: line 1: parser error : StartTag: invalid element name – Foholoc Jun 08 '21 at 13:20
  • So its not a valid xml then. If you just use var_dump($return); it should display the result as a string including the xml-Tags if present. – Chris Jun 08 '21 at 13:23
  • Though in the page source it does has XML tags present ,
    <![CDATA[ , could the "!" be the reason it fails ?
    – Foholoc Jun 08 '21 at 13:26
  • If you have a CDATA Element you need to parse it differently (https://stackoverflow.com/a/20431742/16102690) – Chris Jun 08 '21 at 13:34
  • $client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl'); $result = $client->getVehicleDetails('spwf87','hk8*9jd'); $content = simplexml_load_string( $result , null , LIBXML_NOCDATA ); $json = json_encode($content); $content = json_decode($json,TRUE); var_dump($content); , still results in that same error of.... – Foholoc Jun 08 '21 at 13:45
  • Warning: simplexml_load_string(): Entity: line 1: parser error : StartTag: invalid element name in index.php on line 15 Warning: simplexml_load_string(): <![CDATA[5002386176AHTHA3CD503427515 – Foholoc Jun 08 '21 at 13:45
  • A hacky solution would be:
    <![CDATA[5002386176AHTHA3CD503427515]]>
    '; $content = simplexml_load_string( $return, null, LIBXML_NOCDATA); $content = simplexml_load_string($content->pre); $json = json_encode($content); $content = json_decode($json,TRUE); var_dump($content);
    – Chris Jun 08 '21 at 13:59
  • simplexml_load_string( $result , "SimpleXMLElement" ,LIBXML_NOCDATA | LIBXML_NOBLANKS); didnt work either – Foholoc Jun 08 '21 at 14:00
  • Anythin apart from the hacky one ? There are still fields left in the response I have to put out. Thanks alot for the feedback! – Foholoc Jun 08 '21 at 14:11