PHP数组在HTML页面中显示为纯文本

时间:2019-07-31 18:04:46

标签: php html arrays

我的IIS站点上有PHP和HTML文件,并试图获取同一页面上显示的表单的输出。我遇到的问题是加载HTML页面时,我看到数组信息在该页面上显示为纯文本。我已定义表单操作=“”。另外,当我定义了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>

1 个答案:

答案 0 :(得分:0)

$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>
相关问题