вівторок, 29 січня 2013 р.

function savePushURI($file,$uri)
{
 $fh = fopen($file,"r+");
 if ($fh) {
  echo "File $file found<br>\n";
  $xmls = "";
  while (!feof($fh)) {
    $buf=fgets($fh, 4096);
    $xmls = $xmls . $buf;
  }
  libxml_use_internal_errors(true);
  $sxe = simplexml_load_string($xmls);
  if ($sxe) {
     echo "File $file has right XML structure<br>\n\n";
     fclose ($file);
     $fh = fopen ($file,"w");
     if (!$fh) {
       echo "ERROR: can not open file $file for writing. Do nothing. <br>\n";
       return;
     }
     $channel = $sxe->addChild('channel');
     $channel->addChild('uri',$uri);
     $channel->addChild('count',"0");
     $channel->addChild('toast',"1");
     fwrite($fh, $sxe->asXML());
     fclose($fh);
     echo "New record to $file had added successfully<br>\n\n";
     return;
  } else {
     echo "File $file has wrong XML structure. Erasing and creating new one.<br>\n\n";
     foreach(libxml_get_errors() as $error) {
       echo "\t", $error->message;
     }
     fclose ($file);
     $fh = fopen ($file,"w");
     if (!$fh) {
       echo "ERROR: can not create file $file. Do nothing. <br>\n";
       return;
     }
  }
 } else   {
     echo "File $file not found, creating new one <br>\n\n";
     fclose ($file);
     $fh = fopen ($file,"w");
     if (!$fh) {
       echo "ERROR: can not create file $file. Do nothing. <br>\n";
       return;
     }
 }
$string = <<<XML
<channels>
 <channel>
  <uri></uri>
  <count></count>
  <toast></toast>
 </channel>
</channels>
XML;
 $sxe = new SimpleXMLElement($string);
 $sxe->channel[0]->uri = $uri;
 $sxe->channel[0]->count = "0";
 $sxe->channel[0]->toast = "1";
 fwrite($fh, $sxe->asXML());
 fclose($fh);
 echo "New file $file had created successfully<br>\n\n";
 return;
}

Building an Address Book with OpenLDAP
LDAP. Часть 1. Настройка отказоустойчивого LDAP сервера
SimpleXML
Проверка портов

Немає коментарів:

Дописати коментар