PHP输出来自HTML输入表单

时间:2016-09-11 05:16:42

标签: php html forms file scraper

让用户在表格文本框中输入一个值,该值取值并将其放入$ html = file_get_html('')并在页面上回显输出值。

<form action="dex.php" method="POST">
<b>Site:</b><input type="text" name="site" />
<input type="submit" name="submit" value="Search" />
</form>  

<?php
include('simple_html_dom.php');

$html = str_get_html('site');
echo htmlspecialchars($_POST['site']);
$html->find('div', 1)->class = 'bar';
$html->find('div[id=site]', 0)->innertext = 'foo';
//echo $html; here doesn't show webpage just results
$html = file_get_html('http://www.myrobotbuddy.com');
//$html - file_get_html(' '); from form input
echo file_get_html('$html')->plaintext;
echo $html; //shows website also 
?>

1 个答案:

答案 0 :(得分:0)

我只猜测你想要达到的目标,但是:

首先将表单输入到变量:

if (isset($_POST['submit'])) {
    $site = htmlspecialchars($_POST['site']);
}

然后:

if(isset($site)){
    $html = str_get_html($site);
}