简体   繁体   中英

Split an html document into multiple documents on form submit

I want to submit html into a text area and then on submit I want it to read the file, find the class selector and break down the html into multiple html files and save them in a directory.

Any ideas on how this could be achieved?

For example let say that I submit this into a textarea and I hit submit :

<table class="yoda">
    <tr>
        <td></td>
    </tr>
</table>
<table class="yoda">
    <tr>
        <td></td>
    </tr>
</table>

On submit I want to grab each yoda and save it in a new html file in a directory.

Thank you all in advance. I am not sure if I need to Use php to achieve this or if I need to use javascript.

You have two options

  1. Submit the HTML normally via submit to PHP and use something like SimpleDOM library or PHP native DOM/XML methods to parse and save it as individual snippets ( best method )

  2. Parse the HTML on the client (using jquery or native ) and submit it as JSON to PHP (remember to escape HTML strings). Process JSON using PHP on the server and save the snippets.

textarea inside of parsed document (HTML document).

submit anything in use of an object inside of parsed document is possible.

but split of submitted data ... use server software like php.

Javascript works on client.

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