dpwo36915 2017-06-03 06:54
浏览 53
已采纳

在PHP中通过类字段填写HTML输入类型

In my project I have a HTML form that is included in my Php file. The HTML file has some JavaScript methods to fill automatically, anyways. In first step The Php connect to a remote device via SSH and run some commands. The Php has a class and some functions, In my next step I should read the data that had inserted in the remote device via SSH and fill out in HTML form. I can read the data, and can display it via echo. ( as you will see here ) But how can I display that value into my HTML input type value? Here is my HTML code : ( I write it briefly, cause it is too long and no need to write all)

     <div id="linkname" >
                <label>Wireless Link Name</label>   

                <input type="text" name="ssid" id="ssid"><br>  
    </div>

Here is my Php File class and methods :

         <?php

        class SSHCommand{

            public $ssh;

            include('./view/config.html');   
            include('Net/SSH2.php');    


        class SSHCommand{

        public function display(){

        session_start();

        $username=$_SESSION['username'];
        $password=$_SESSION['password'];
        $ip=$_SESSION['ip'];
        $this->ssh=new Net_SSH2($ip);

       if($this->ssh->login($username, $password)) { 
          $my_array= explode("
", $this->ssh->exec('some command'));
          foreach($my_array as $cat) {  
         if(strpos($cat, "name=") !== false) { 
         // I should here insert the $cat value into  ssid input
        break;
    } else { 
        // Do nothing
    }
}   
        } else echo 'wrong';
    }
    }
        $sshCommand=new SSHCommand(); 
        $sshCommand->display();
    ?>

As you see I fill an array, I search for a specific text in the array, like

name= 

, and want insert that value into the input type ssid.

How can I do that in Php code? Any Idea?

  • 写回答

1条回答 默认 最新

  • doujieluo5875 2017-06-03 08:47
    关注

    The only way I can think of doing that, considering how you are importing the html file, is to call a javascript script to pass a value to the input.

    if(strpos($cat, "name=") !== false) { 
      echo '<script>document.querySelector("#ssid").value = "' . $cat . '";</script>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作