简体   繁体   English

在表单提交中将html文档拆分为多个文档

[英]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. 我想将html提交到文本区域,然后在提交时我希望它读取文件,找到类选择器,然后将html分解为多个html文件并将其保存在目录中。

Any ideas on how this could be achieved? 关于如何实现的任何想法?

For example let say that I submit this into a textarea and I hit submit : 例如,假设我将其提交到textarea中,然后点击了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. 在提交时,我想获取每个yoda并将其保存在目录中的新html文件中。

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. 我不确定是否需要使用php来实现这一目标,或者是否需要使用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 ) 通常通过提交到PHP来提交HTML,并使用诸如SimpleDOM库或PHP本机DOM / XML之类的方法将其解析并保存为单独的片段( 最佳方法

  2. Parse the HTML on the client (using jquery or native ) and submit it as JSON to PHP (remember to escape HTML strings). 解析客户端上的HTML(使用jquery或native),并将其作为JSON提交给PHP(记住要转义HTML字符串)。 Process JSON using PHP on the server and save the snippets. 在服务器上使用PHP处理JSON并保存代码段。

textarea inside of parsed document (HTML document). 解析文档(HTML文档)内部的textarea。

submit anything in use of an object inside of parsed document is possible. 使用解析的文档内部的对象提交任何内容都是可能的。

but split of submitted data ... use server software like php. 但拆分提交的数据...使用类似php的服务器软件。

Javascript works on client. Javascript适用于客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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