代码之家  ›  专栏  ›  技术社区  ›  da5id

使用PHP检查远程文件是否为格式良好的XML

  •  8
  • da5id  · 技术社区  · 17 年前

    我有一个PHP驱动的站点,其中包含一个XML提要,该提要由ASP远程提供(即,XML提要url的顺序为: http://remote.com/client.asp ).

    蒂亚。

    1 回复  |  直到 17 年前
        1
  •  21
  •   cletus    17 年前

    使用 cURL 得到结果并 simplexml well-formed .

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "http://remote.com/client.asp");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    if (simplexml_load_string($output)) {
      // well-formed XML
    } else {
      // it isn't
    }