开发者

Finding name attributes inside a tag using php

开发者 https://www.devze.com 2022-12-17 06:04 出处:网络
i want to find the name attribute with in a tag in a form using php4 . Does any one help me how it find..

i want to find the name attribute with in a tag in a form using php4 . Does any one help me how it find..

eg

<input type="text" name="txt_name开发者_StackOverflow中文版" value="" >

I want to know name of all the fields


You need a library/code which implements an HTML DOM, look at these SO questions for more information.


When you submit a form, a url is send to the server in the form "name=value&name1=value1" etc. Here the "name" stands for the attribute "name" of an html element. So If you are using the $_GET or a $_POST then you can get the form item names in an array as follows

$names=array();
foreach($_GET as $key => $value)
{
  $names[] = $key;
}
print_r($names);


You can use simple html dom as mentioned by Ignacio Vazquez-Abrams

Add it in your code like this require_once('Simple_html_dom.php');

To use it I initialized it using this line

$html = new Simple_html_dom();

Load a page or link using the line

$html->load_file('http://www.yourste.com/yourpage.php');

to parse and find this element

$e = $html->find("input", 0);

the echo the value of attribute name

echo $value = $e->name
0

精彩评论

暂无评论...
验证码 换一张
取 消