简体   繁体   中英

PHP Simple Html Dom parsing a php form

I have this php page:

exercice_submit.php?exerciseId=7

Which has several nested div inside

<div id="container">
<div id="content">
<div id="content_main">

Inside last div there is a form:

<form action="/modules/exercice/exercice_submit.php" method="post">

I want to cut all the other html tags and keep only what is included inside form. Can you please help me parse this page?

What I used is PHP Simple HTML DOM and I wrote:

    // example of how to use basic selector to retrieve HTML contents
    include('../simple_html_dom.php');
    
    // get DOM from URL or file
    $html = file_get_html('exercice/exercice_submit.php');
    
    echo $html->find("#content_main",0);
    echo $html->outertext
    
    ?>

This doesn't seem to work. If you can help me maybe you know a way of changing submit button target to submit to different php than what it is.

Thanks in advance for all potential answers.

I've not used file_get_html, but you could use file_get_contents to load it into a string then use substr in conjunction with strpos on "<form" and "</form>" to get the form.

http://www.php.net/manual/en/function.strpos.php

http://www.php.net/manual/en/function.substr.php

http://www.php.net/file_get_contents

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM