php - PHP数组在HTML页面中显示为纯文本
问题描述
我的 IIS 站点上有 PHP 和 HTML 文件,并试图获取显示在同一页面上的表单的输出。我遇到的问题是当我加载 HTML 页面时,我看到数组信息在该页面上显示为纯文本。我已经定义了表单 action = ""。或者,当我定义了 form action = "file.php" 时,我得到了想要的结果,但是在一个新页面上。我查看了此处的链接,但似乎没有提供我要查找的内容。我尝试在每一行上添加标签,这有点帮助,但我仍然将数组视为纯文本。这是我所拥有的:
<form action="" method = "POST">
MAC Address of phone: <input type="text" name="phonemac"><br><br>
<input type="submit" value="Check Phone Status">
</form>
<?php
$host = "server.com";
$username = "*****";
$password = "*****";
$context =
stream_context_create(array('ssl'=>array('allow_self_signed'=>true)));
$client = new SoapClient("C:\inetpub\wwwroot\PhoneSetup\AXLAPI.wsdl",
array('trace'=>true,
'exceptions'=>true,
'location'=>"https://".$host.":8443/axl",
'login'=>$username,
'password'=>$password,
'stream_context'=>$context
));
$response = $client->getPhone(array("name"=>"$_POST[phonemac]"));
$array = json_decode(json_encode($response), true);
echo $array['return']['phone']['description'];echo '<br><br>';
echo $array['return']['phone']['name']; echo;
?>
</body>
</html>
解决方案
这个
$myArray = json_decode($data, true);
echo $myArray[0]['id']; // Fetches the first ID
echo $myArray[0]['c_name']; // Fetches the first c_name
// ...
我会用你的代码写一个例子
$array = json_decode(json_encode($response), true);
echo $array[0]['phone']
echo $array[0]['description'];
echo '</br></br>';
echo $array[0]['phone'];
echo $array[0]['name'];
你的代码就像
<form action="" method = "POST">
MAC Address of phone: <input type="text" name="phonemac"><br><br>
<input type="submit" value="Check Phone Status">
</form>
<?php
$host = "server.com";
$username = "*****";
$password = "*****";
$context =
stream_context_create(array('ssl'=>array('allow_self_signed'=>true)));
$client = new SoapClient("C:\inetpub\wwwroot\PhoneSetup\AXLAPI.wsdl",
array('trace'=>true,
'exceptions'=>true,
'location'=>"https://".$host.":8443/axl",
'login'=>$username,
'password'=>$password,
'stream_context'=>$context
));
$response = $client->getPhone(array("name"=>"$_POST[phonemac]"));
$array = json_decode(json_encode($response), true);
echo $array[0]['phone']
echo $array[0]['description'];
echo '</br></br>';
echo $array[0]['phone'];
echo $array[0]['name'];
?>
<body>
</html>
推荐阅读
- python - 用替换数据填充缺失的数据
- c# - 在等待时,当控制权交给调用者时,它是否处理 for 循环的下一次迭代(是否等待返回任务?)?
- python - 将 Matlab 的过滤器设置转换为 Python 的 scipy.signal.buttord
- azure - 如何调查 Azure VM 中的出口使用情况
- redis - redis-py 客户端是否支持 Redis Search 和 Redis JSON 支持
- python - 如何在设定的时间后终止函数?
- ruby-on-rails - 无法从 RubyMine 在 WSL 中运行 rspec
- json - 如何在颤动中显示 JSON 嵌套的 ArrayList 项?
- html - 如何组合多个xml并为组合的XML准备XSLT 以上是一个XML的XSLT
- javascript - 如何将属性从反应组件传递给其父级?