php - How to add elements to existing HTML using DomDocument? -
i have following select drop-down
<select name="set_login_redirect" id="set_login_redirect"> <option value="dashboard">wordpress dashboard</option> <option class="level-0" value="1881">activate</option> <option class="level-0" value="2109">affiliate area</option> <option class="level-0" value="429">cart</option> <option class="level-0" value="430">checkout</option> </select>
how use php domdocument
class add new option
element select
drop-down.
for example, want add code below html above.
how can done?
<option class="level-0" value="27">the word</option>
i couldn't answer wrote php function dirty regex solve it.
/** * append option select dropdown * * @param string $option option add * @param string $select select dropdown * * @return string */ function pp_append_option_to_select($option, $select) { $regex = "/<select ([^<]*)>/"; preg_match($regex, $select, $matches); $select_attr = $matches[1]; $a = preg_split($regex, $select); $join = '<select ' . $select_attr . '>' . "\r\n"; $join .= $option . $a[1]; return $join; }
example
$a = pp_append_option_to_select('<option value="current">current page</option>', $xml); print_r($a);
hoping finds useful someday.
am still open better way of doing using domdocuement class.
Comments
Post a Comment