使用PHP如何刮除所有字段名称并输出到文本文件?

时间:2022-10-04 09:59:37

what i want to try to do is be able to enter say a url onto a variable and once executed the page will scrape all input field names and export it to a text file.

我想要尝试做的是能够在变量上输入一个url,一旦执行该页面将刮掉所有输入字段名称并将其导出到文本文件。

for example.

if i have

如果我有

<input type="text" name="firstname">
<input type="text" name="lastname">
<select name="sex">
<option>...</option>
...
</select>

the output would be

firstname
lastname
sex

whats a simple way of doing it?

这是一个简单的方法吗?

thanks

1 个解决方案

#1


Check out Simple HTML DOM. It would let you do something like this:

查看简单的HTML DOM。它会让你做这样的事情:

$html = file_get_html($my_address);
foreach($html->find('input, select, textarea') as $input) {
    $names[] = $input->name;
}
file_put_contents('my_output.txt', implode("\n", $names));

#1


Check out Simple HTML DOM. It would let you do something like this:

查看简单的HTML DOM。它会让你做这样的事情:

$html = file_get_html($my_address);
foreach($html->find('input, select, textarea') as $input) {
    $names[] = $input->name;
}
file_put_contents('my_output.txt', implode("\n", $names));