parsing - Parse HTML adding ID to all <input>s using NAME in PHP -
i'm trying take html document in php (that have no command over) , ensuring each input has id. if there's no id need add together 1 using whatever name has been set.
for example:
input type="text" name="something" value="something else"
i need parse to:
input type="text" name="something" id="something" value="something else"
i must entire document.
i have search solution have come empty handed.
ok misunderstood! reply number 2 here:
$dom = new domdocument; $dom->load('yourdoc.html');// load document $inputs = $dom->getelementsbytagname("input"); //get inputs for($i=0; $i<$inputs->length; $i++){ // every input found $thisname = $inputs->item($i)->getattribute("name"); // set name in variable $inputs->item($i)->setattribute("id",$thisname); // set id same } $dom->save('yourdoc.html'); //save document
this has closer want, surely?
no parsers, simple dom work.
php parsing dom html-parsing
No comments:
Post a Comment