PHP-cURL接收xml
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP-cURL接收xml相关的知识,希望对你有一定的参考价值。
<?php /****************************************** * POST TO REMOTE SCRIPT ******************************************/ //fake data to send via cURL $post = 'var1=hello&var2=world'; //replace with your post destination url $url = "http://example.com/script.php"; //start cURL //define curl: set where the post is going //define curl: set that you want the response //to be store in a variable and not display on screen //define curl: set what you are sending //If the post was not successful curl_exec will return false. //If successful store response in variable //close the connection //Trim the response from excess white space //NOTE:It may be necessary to do further sanitizing of the string //enable error reporting //parse the xml response string //store the original xml in an array //if simplexml_load_string() fails, it returns false. //if it returns false, collect the errors and print them to the screen if (!$doc) { foreach ($errors as $error) { echo display_xml_error($error, $xml); } }else{ //Successfull parsed the xml string } }else{ //There was a problem with cURL executing. Do you have cURL on this server? echo "cURL was not able to execute"; //close connection } //Helper Function For Displaying the Errors function display_xml_error($error, $xml){ $return = $xml[$error->line - 1] . " "; switch ($error->level) { case LIBXML_ERR_WARNING: $return .= "Warning $error->code: "; break; case LIBXML_ERR_ERROR: $return .= "Error $error->code: "; break; case LIBXML_ERR_FATAL: $return .= "Fatal Error $error->code: "; break; } " Line: $error->line" . " Column: $error->column"; $return .= " File: $error->file"; } return "$return -------------------------------------------- "; } ?>
以上是关于PHP-cURL接收xml的主要内容,如果未能解决你的问题,请参考以下文章