【问题标题】:PHP array diplaying as plain text in HTML pagePHP数组在HTML页面中显示为纯文本
【发布时间】:2019-08-01 02:13:20
【问题描述】:

我的 IIS 站点上有 PHP 和 HTML 文件,并试图获取显示在同一页面上的表单的输出。我遇到的问题是当我加载 HTML 页面时,我看到数组信息在该页面上显示为纯文本。我已经定义了表单 action = ""。或者,当我定义了 form action = "file.php" 时,我得到了想要的结果,但是在一个新页面上。我查看了链接here,但似乎没有提供我想要的东西。我尝试在每一行上添加标签,这有点帮助,但我仍然将数组视为纯文本。这是我所拥有的:

<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>

【问题讨论】:

标签: php html arrays


【解决方案1】:

这个

$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>

【讨论】:

  • 感谢您的建议,但是问题始于以 array('allow_self_signed'=&gt;true 变量中的 array('allow_self_signed'=&gt;true 字符串开头的数组条目。很抱歉没有澄清。运行您建议的内容会产生相同的结果。
  • 有人吗?我更新了表单操作声明以符合 HTML5 标准。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-27
  • 1970-01-01
  • 2019-12-26
  • 1970-01-01
  • 2013-05-19
  • 2017-02-23
  • 1970-01-01
相关资源
最近更新 更多