Jump to content

API returns <![CDATA


epicconstruct

Recommended Posts

I accessed the API for 'getclientdata' and was able to get it to run successfully. However some of the fields returned their contents wrapped in <![CDATA[ {$data} ]]> . Particularly firstname, lastname, companyname, and lastlogin. All of the other data returned as regular text.

 

Does anybody know why it returns this way? Or a decent way of handling the oddly returned data?

 

Overall, it seems the API documentation is somewhat lacking. I'm actually planning on writing a class I can use to hit the API instead of pasting their long API example in every piece of code I'd like to make a call. Has anybody done this already or have any more information on the API?

 

Thanks

Link to comment
Share on other sites

I altered the example code. It seems to have fixed the problem.

I'm still curious though if anybody has any comments on the original post.

 

$data = explode(";",$data);
foreach ($data AS $temp) {
 $temp = explode("=",$temp);
 $results[$temp[0]] = $temp[1];
}

 

$data = explode(";",$data);
 foreach ($data AS $temp) {
 $temp = explode("=",$temp);
 $temp[1] = str_replace('<![CDATA[', '', $temp[1]);
 $temp[1] = str_replace(']]>', '', $temp[1]);
 $results[$temp[0]] = $temp[1]);
}

Link to comment
Share on other sites

<![CDATA embedded textvalues are protected from interpreting into a wrong markup.

just preg match the result:

 

$clientarr = whmcsapiGetClientsDatabyID('1');
// custom function test with client ID "1" above
echo "<pre>clientarr"; print_r($clientarr); echo "</pre>";
preg_match('%^\<\!\[CDATA\[(.*)\]\]\>$%',$clientarr['lastlogin'],$match);
echo "<pre>match"; print_r($match); echo "</pre>";
$lastlogin = $match[1];

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated