Search code examples
phphtmlformsfilescraper

PHP output from HTML input Form


Have the user input a value in a form text box that takes the value and puts it in $html = file_get_html(' ') and echoes output value on the page.

<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 
?>

Solution

  • I'm only guessing what you want to achieve, but:

    First get the form input in to a variable:

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

    then:

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