Check for Valid XML with PHP

Simple function to check if XML is valid. It just loads the XML into DOMDocument and checks for errors.

*  Takes XML string and returns a boolean result where valid XML returns true
function is_valid_xml ( $xml ) {
    libxml_use_internal_errors( true );
    $doc = new DOMDocument('1.0', 'utf-8');
    $doc->loadXML( $xml );
    $errors = libxml_get_errors();
    return empty( $errors );

Post XML with HTTPS Authentication using PHP and cURL

Recently I needed to post XML to a particular API and this API required HTTPS authentication. So I needed to send a username / password with the request.

This was pretty straightforward in C#.NET ( at least from my foggy memory ). You needed to use NetworkCredentials. But it was a bit difficult to find a similar way of doing this in PHP… but eventually I found this gem.

This uses cURL which is just a library to send and receive data from remote sites. Now all I needed was a neat way of using cURL to post XML… and I found a neat implementation here.

Two plus two and you get …
Continue reading “Post XML with HTTPS Authentication using PHP and cURL”