gpt4 book ai didi

php - XML 输出并排显示

转载 作者:行者123 更新时间:2023-11-28 09:28:19 25 4
gpt4 key购买 nike

我有一个使用 XML 的地理定位 api,这里是示例:http://freegeoip.net/xml/31.44.188.50

我在我的网站上使用了这个 XML api,所以我做了一个地理位置扫描仪,但由于某些原因,当它输出时,IP/国家/邮政编码等。它并排显示,这令人困惑,我的问题是如何让输出低于彼此或在表格中。

我的代码:

    <input type="text" name="username" style="text-align: center;" placeholder=" IP address" />
<input type="submit" name="submit" class="" value="Resolve" />

.`

if (isset($_POST['submit'])) {
$name = $_POST['username'];
$blacklist = array("100.100.100","123.123.123");
$ip = $_SERVER['REMOTE_ADDR'];
if(in_array($name,$blacklist))
{
echo "No";
else
$api1 = file_get_contents("http://freegeoip.net/xml/$name");
echo "<div style='display: block; color: red; font-weight: bold;>' $api1 </div>";


}
}

?>

它看起来是这样的:31.44.188.50 NL Netherlands 07 Noord-Holland Amsterdam 52.35 4.9167

这就是我想要的:

  • IP 地址:31.44.188.50
  • 国家:荷兰荷兰
  • 城市:Noord-Holland Amsterdam

等等

最佳答案

使用 SimpleXML:

$xml = simplexml_load_file("http://freegeoip.net/xml/31.44.188.50");
echo 'IP : ', $xml->Ip, '<br>';
echo 'Country code : ', $xml->CountryCode, '<br>';
echo 'Country name : ', $xml->CountryName, '<br>';
echo 'City : ', $xml->City, '<br>';

输出:

IP : 31.44.188.50
Country code : NL
Country name : Netherlands
City : Amsterdam

有关文档的更多示例和解释: http://php.net/manual/en/book.simplexml.php

关于php - XML 输出并排显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25813233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com