Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

elements from a xml file

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

elements from a xml file

Postby Techboy992 » Sun Apr 06, 2014 6:42 pm

Hi am trying to get some entrys from a xml file:
Code: Select all
<license>
   <server_ip>some ip</server_ip>
   <domain>some domain</domain>
   <license_key>some license key</license_key>
   <allowed>1000</allowed>
   <used>1</used>
   <expire>2100-12-31</expire>
   <update>2014-12-31</update>
        <check>1a1937f9e47ea3d1402749aae9a679c9</check>
</license>


What I need is getting the entry's in to variables that I can process with php to check license
Code: Select all
$serverip = entry
$domain = entry
$license = entry
$expire = entry
$update = entry
$check = entry


Some of the above is send to license server with CURL rest is just check in my config file.

Thanks in advance
Brian Olsen
Techboy992
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Apr 06, 2014 6:32 pm

Re: elements from a xml file

Postby adicooldude » Mon Apr 07, 2014 2:34 am

Hi,
try this
Code: Select all
if (file_exists('sample.xml')) {
   # The XML file with bad characters
   $filename = "sample.xml";
   
   # Read file contents to a variable
   $contents = file_get_contents($filename);
   try{
      $xml_response = new SimpleXmlElement($contents, LIBXML_NOCDATA);
      echo ($xml_response->server_ip)."\n";
      echo ($xml_response->domain)."\n";
      echo ($xml_response->license_key)."\n";
      echo ($xml_response->allowed)."\n";
      echo ($xml_response->used)."\n";
      echo ($xml_response->expire)."\n";
      echo ($xml_response->update)."\n";
      echo ($xml_response->check)."\n";
   }catch (Exception $e){
      echo $e;
   }
   
}
adicooldude
New php-forum User
New php-forum User
 
Posts: 10
Joined: Mon Apr 07, 2014 2:26 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.