그누에 관한건 아니지만.. 혹시 xml 파싱 아시는분? php에 관한..

<?
function _parser($tag, $str){
    preg_match_all("/<".$tag.">(.*)<\/".$tag.">/iUs", $str, $match);
    for($i=0, $total=sizeof($match[1]); $i<$total; $i++){
        $match[1][$i]=str_replace("<![CDATA[", "", $match[1][$i]);
        $match[1][$i]=str_replace("]]>", "", $match[1][$i]);
    }
    return $match[1];
}

function test($url){
    $url_parsed = parse_url($url);
    $host = $url_parsed["host"];
    $post = $url_parsed["port"];
    if ($port==0)
            $port = 80;
    $path = $url_parsed["path"];

    if (empty($path))
    $path="/";

    if (empty($host)):
    $host="manya.aquz.biz";
    $path="/t-m?xml";
    endif;

    if ($url_parsed["query"] != "")
        $path .= "?".$url_parsed["query"];
    $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
    $fp = fsockopen($host, $port, $errno, $errstr, 30);
    fwrite($fp, $out);

    $output =0;
    while (!feof($fp)){
        $get_str = fgets($fp, 128);
        if($output == 0 && $get_str=="\r\n"){
            $output = 1;
        }
        if($output) echo $get_str;
    }
    fclose($fp);

    return;
}
?>


위 소스에서
echo test(아무숫자나);

이런식으로 출력하면 아래 주소와 똑같이 출력됩니다.
http://manya.aquz.biz/t-m?xml

function test($url){} 이부분과 return; 을 지우고
echo $get_str을 출력해도 위 주소와 똑같이 출력됩니다.

test() <- 가로안에 뭘 넣는지 모르겠네요. 소스를 퍼온거라서

맨 위에 function _parser($tag, $str) 이 함수는 팁게시판을 참조 했는데요.
http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=49208&sca=&sfl=wr_name%7C%7Csubject&stx=%BD%BA%B3%AA&sop=and

위 주소를 참조하여

$tmp = test(0);
$a = _parser("mod_cband", $tmp);
echo $a;

이런식이나 다른식으로 출력하면 아래와 같은 오류가 뜹니다.


XML 페이지를 표시할 수 없습니다.
XSL 스타일시트를 사용하여 XML 입력을 볼 수 없습니다. 오류를 수정한 다음 새로고침 단추를 누르거나 나중에 다시 시도하십시오.
-------------------------------------------------------------------------------
문서의 최상위 수준이 잘못되었습니다. 'http://manya.aquz.biz/test.php' 리소스를 처리하는 데 오류가 발생했습니다. 줄 46, 위치 13

</mod_cband>Array
------------^


결론은....
일단 xml문서를 통채로 그대로 출력은 됩니다. 변수에 저장도 되는 거 같고..
그런데 거기서 원하는 부분만 출력하는 부분이 잘 안되네요.

어떤 부분이 문제인지 알려주시면 감사하겠습니다. (__)
|

댓글 1개

<?
function _parser($tag, $str){
preg_match_all("/<".$tag.">(.*)<\/".$tag.">/iUs", $str, $match);
for($i=0, $total=sizeof($match[1]); $i<$total; $i++){
$match[1][$i]=str_replace("<![CDATA[", "", $match[1][$i]);
$match[1][$i]=str_replace("]]>", "", $match[1][$i]);
}
return $match[1];
}

function test($url){
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$post = $url_parsed["port"];
if ($port==0)
$port = 80;
$path = $url_parsed["path"];

if (empty($path))
$path="/";

if (empty($host)):
$host="manya.aquz.biz";
$path="/t-m?xml";
endif;

if ($url_parsed["query"] != "")
$path .= "?".$url_parsed["query"];
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($fp, $out);

$output =0;
while (!feof($fp)){
$get_str .= fgets($fp, 128);
if($output == 0 && $get_str=="\r\n"){
$output = 1;
}
}
fclose($fp);

return $get_str;
}
$data= test($url);

list($channel) = _parser("mod_cband", $data);

$channel_item = _parser("usages", $channel);
for($i=0, $tot=sizeof($channel_item);$i<$tot; $i++){
$item = $channel_item[$i];
list($total) = _parser("total", $item);
list($kbps) = _parser("kbps", $item);
list($rps) = _parser("rps", $item);
list($connections) = _parser("connections", $item);
echo '<li>total='.$total.' kbps='.$kbps.' rps='.$rps.' connections='.$connections.'</li>';
}


?>
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
18년 전 조회 1,356
18년 전 조회 3,673
18년 전 조회 1,522
18년 전 조회 1,565
18년 전 조회 1,606
18년 전 조회 1,512
18년 전 조회 1,561
18년 전 조회 1,580
18년 전 조회 2,531
18년 전 조회 2,551
18년 전 조회 1,512
18년 전 조회 1,721
18년 전 조회 1,524
18년 전 조회 1,502
18년 전 조회 1,514
18년 전 조회 1,424
18년 전 조회 1,561
18년 전 조회 1,531
18년 전 조회 1,726
18년 전 조회 1,739
🐛 버그신고