0

I am using below script to fetch API data from 3rd party site.

function PPCcURLAPIAccess($xml_url)
{
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $xml_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ($ch, CURLOPT_HEADER, false);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0); // Use 0 to wait indefinitely. 
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSLVERSION, 5);
    $xml = curl_exec($ch);
    curl_close($ch);
    return $xml;
}


$xml_url = "$xml_url = "https://api.sitename.com/api/reports/api_get_daily.asp?User=00012345&Key=abcdefghijklmnop&fromDate=11/12/2022&toDate=12/12/2022&mid=25";

$xml_report_data = simplexml_load_string(PPCcURLAPIAccess($xml_url));

foreach ($xml_report_data as $report_data):
    $trans_id=$report_data->TRANSID;
    $member_id=$report_data->MEMBERID;
    $extension=$report_data->EXTENSION;
    $icutynum=$report_data->ICITYNUM;
    $callerid=$report_data->CALLERID;
    $type=$report_data->TYPE;
    $start_time=$report_data->START;
    $accepted_time=$report_data->ACCEPTED;
    $end_time=$report_data->END;
    $indur=$report_data->INDUR;
    $out=$report_data->OUT;
    $online=$report_data->ONLINE;
    $status=$report_data->STATUS;
    $profit=$report_data->PROFIT;
endforeach;

XML data are something like this:

<DATABASE>
    <RECORD>
        <TRANSID>1348818</TRANSID>
        <MID/>
        <EXT>0</EXT>
        <USER>00012345</USER>
    </RECORD>
    .
    .
    .
    so on...
</DATABASE>

But I am getting below warning when running the code. Please help me to resolve these warnings.

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Space required after the Public Identifier in

Warning: simplexml_load_string() [function.simplexml-load-string]: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/str in

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 3: parser error : Opening and ending tag mismatch: META line 3 and HEAD in

Warning: simplexml_load_string() [function.simplexml-load-string]: in

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 6: parser error : Opening and ending tag mismatch: hr line 5 and BODY in

Warning: simplexml_load_string() [function.simplexml-load-string]: in

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 6: parser error : Opening and ending tag mismatch: BODY line 4 and HTML in

Warning: simplexml_load_string() [function.simplexml-load-string]: in

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 7: parser error : Premature end of data in tag HEAD line 2 in

Warning: simplexml_load_string() [function.simplexml-load-string]: in

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 7: parser error : Premature end of data in tag HTML line 2 in

Warning: simplexml_load_string() [function.simplexml-load-string]: in

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in

Warning: Invalid argument supplied for foreach() in

  • You appear to be loading HTML. SimpleXML is meant to handle strict XML. HTML is a subset of XML but does not adhere to all the rules. Try loading it through the DOM's HTML loader then handing it off to SimpleXML. See here: https://stackoverflow.com/a/6635878/1456201 – Jim Jan 26 '22 at 12:15

0 Answers0