티스토리 뷰

SWDesk/Web

PHP를 이용한 XML 및 HTML 파싱

bizmaker 2020. 1. 25. 00:40
<!DOCTYPE.html>
</html>
<html>
<head>
<?php

 function Test01(){ // Not completed... File error, 2018.08.20
  
 // Ref. : https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=74051
  include "HttpClient.class.php";

//https://pat.im/817  
  echo realpath(__FILE__)."<br>";
  echo basename(__FILE__)."<br>";
  echo $_SERVER['DOCUMENT_ROOT']."<br>";

  $host = "www.bilientsvc.net";
  $url = "/Tests/PHPPost_Client01.php";
  $post = array('p1'=>'Hello', 'p2'=>'World');
  $cookie = array('c1'=>'1234', 'c2'=>'5678');
  $Path0 = '/mnt/HDD1/webroot/Tests/';
  $Path1 = '/HDD1/webroot/Tests/';
  $file = array(
   array('name'=>'File1', 'path'=>'/mnt/HDD1/webroot/Tests/TestImage01.jpg')
  );
  //if(function_exists('HTTPClient')) echo "Yes...";
  $client = new HttpClient($host);
  if($client == null) echo "client : null";
  //if($cookie) $client->setCookies($cookie);
  $ret = $client->post($url, $post, $file);
  //$ret = $client->post($url, $post);
  if($ret == null) echo "ret : null";

  $pageContents = "None";

  $pageContents = $client->getContent();

  echo "<Rst>".$pageContents."</Rst>";
 }

 function Test02(){ // Failed, 2018.08.20
// Ref : http://php.net/manual/it/httprequest.send.php
  //include "./http.php";
  $ClientURL ="https://www.bilientsvc.net/Tests/PHPPost_Client01.php";
  $r = new HttpRequest($ClientURL, HttpRequest::METH_POST);
  $r->setOptions(array('cookies' => array('lang' => 'de')));
  $r->addPostFields(array('p1' => 'Hello', 'p2' => 'World'));
  //$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
  try {
   echo $r->send()->getBody();
  } catch (HttpException $ex) {
   echo $ex;
  }
 }

 function Test03(){ // Failed, 2018.08.20
  include "Client.php";

  $ClientURL ="http://www.bilientsvc.net/Tests/PHPPost_Client01.php";
  $client = new \GuzzleHttp\Client();
  $request = $client->get($ClientURL);
  $response = $request->getBody();
  if($response) echo $response;
  else echo "null";
 }

 function Test04(){
  copy("http://www.bilientsvc.net/Tests/TestImage02.jpg", './TestImage021.jpg');
 }

 function Test05(){ // XML Parsing
  $pageContents = file_get_contents("http://www.bilientsvc.net/Tests/PHPXML01.php");
  $result_xml = simplexml_load_string($pageContents);
  //print_r($result_xml);

  echo $result_xml->employee[0]->firstName;
 }

 function Test06(){ // HTML Parsing, Completed, 2018.08.20
 // https://www.tutorialspoint.com/php/php_dom_parser_example.htm
  include "HttpClient.class.php";
  //echo phpinfo();

  $host = "www.bilientsvc.net";
  $url = "/Tests/PHPXML02.php";
  $post = array('p1'=>'Hello', 'p2'=>'World');
  $client = new HttpClient($host);
  if($client == null) echo "client : null";
  $ret = $client->post($url, $post);
  if($ret == null) echo "ret : null";

  $pageContents = $client->getContent();
  echo $pageContents;
  echo "<br> ---------------------------------------- <br>";

  $dom = new DOMDocument('1.0', 'utf-8');
  //echo "DOM : ".$dom;
  $dom->loadHTML($pageContents);
  //echo "DOM : ".$dom;
  $dom->preserveWhiteSpace = false;
  $body = $dom->getElementsByTagName('body');
  $data = $body->item(0)->getElementsByTagName('data');
  $Emp1 = $data->item(0)->getElementsByTagName('employee');
  //$data1s = $data->item(0)->saveXML();
  echo $Emp1->item(0)->nodeValue;

  echo "<br> ---------------------------------------- <br>";
  //$data11 = $data1->getElementsByTagName('employee');
  //print_r($data1);
  //echo $Body;

 }

?>

<title>
Tests ...
</title>
</head>
<body>
<h1> PHP Post Test(Server01) </h1>
<?php
 $CommandOption = $_GET['CommandOption'];
 echo "-------------------------------------<br>";
 echo "Command Option : ".$CommandOption."<br>";
 echo "-------------------------------------<br>";
 if($CommandOption == '1'){
  echo "Run Test01()";
  Test01();
 }
 if($CommandOption == '2') Test02();
 if($CommandOption == '3') Test03();
 if($CommandOption == '4') Test04();
 if($CommandOption == '5') Test05();
 if($CommandOption == '6') Test06();
?>

</body>
</html>

https://bilient-power-manager.tistory.com/2

 

파워 박스(BPM-PB) 설명서

<주의 사항> 사용 중 본 기기 분해하여 커버를 개방하지 말 것. 케이블 또는 파워박스에 과도한 힘을 가하지 말 것. 내부 퓨즈가 끊긴 경우, 모든 전원을 분리시킨 후 안전한 관리 상황을 확인한 후에 커버를 개방..

bilient-power-manager.tistory.com

 

반응형

'SWDesk > Web' 카테고리의 다른 글

[BMS] Bilient Monitoring System - Test02  (3) 2020.03.29
[Web] 공공데이터 활용 - 나라장터  (0) 2020.02.27
Javafx용 예제(1)  (0) 2020.01.22
[MySQL] DB 백업 및 복원  (0) 2020.01.20
Kotlin Excersing Example  (0) 2019.12.13