doubeizhong5178 2015-02-18 02:37
浏览 126

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>
  • 写回答

1条回答 默认 最新

  • dshw124502 2015-02-18 02:45
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度