The html select code generated by using (wp_dropdown_categories) WordPress function and i want to convert it into an array urgently.
<select name="selectname1" id="selectId1" class="postform">
<option value="0">Recent Posts</option>
<option class="level-0" value="1">Uncategorized</option>
<option class="level-0" value="2">World News</option>
<option class="level-1" value="3"> Political</option>
So i need to be something like that (Key, Value)
Array('Recent Posts' => '0',
'Uncategorized' = > '1',
'World News' = > '2',
' Political' = > '3'
);
Try this:
Since you want it quickly, here’s a quick-n-dirty regex solution:
However, you really should not tokenise/parse HTML with regular expressions, instead use an XML/DOM class.