PHP简单的HTML DOM解析器获取用户输入并从网页获取值并返回该值

I have php page where the user can enter the mutual fund ticker symbol.

I am trying to enable the user to click a button and have the name of the fund display of the page.

I assume that I need to pass the value from the input box to a separate php page. I have a php page that uses php simple html dom parser and if I hard code the ticker symbol the php page will extract the name of the fund from a web page.

I am not clear on the concept of how I pass the variable from the input box to the the other php file or whether I even need a separate php file.

Is it possible to keep this all on the same php page? Right now, on the separate php page, I have a variable that holds the fund name.

I'm not sure how to display that value on the first php page. If somebody could help me with the concept, I can write some code.

Below is the page named getFundName.php which gets the fund name.

<?php
      include('simple_html_dom.php');
      $firstvar = "http://www.marketwatch.com/investing/fund/";
      $secondvar = "LLPFX";
      $combovar = $firstvar . $secondvar;

      $html = new simple_html_dom();
      $html->load_file($combovar); 

      $getFundName = $html->find('#instrumentname',0);
      print_r($getFundName->plaintext);
      //echo $getFundName->plaintext;
      $html->clear(); 
      unset($html);
?>
Below is my guess at the other code, but obviously it's not functioning.

<?php
     some php code here
?>
<html>
   <body>
      <script language="JavaScript">
            function getFundName() { 
              var xhr=createXHR();
              xhr.open("GET", "getFundName.php",true);
              xhr.onreadystatechange=function()
              { 
                  if(xhr.readyState == 4)
                  {
                     document.getElementById("displayFundNameHere").innerHTML= xhr.responseText;    
                  } 
              };
        }
     </script>
  <div id="displayFundNameHere"><div>
   Fund Symbol: <input type="text" id='fundSymbolBox'/>
   <input type="button" value="Get Fund Name" onclick="getFundName()"/>
   </body>
</html>

What you are going to want to do is setup the page to take input, and do an AJAX request to a PHP page which will return the data you want.

Looking at your code, you seem most of the way there, don't forget that you need to call xhr.send() after you assign your callback.

If you wanted to keep it all on the same page, you could wrap everything in a form which posts to itself and have the PHP code pull out the data from the POST variable and fill in the data without using AJAX or javascript.