I'm making an online script manager using php and would like a little help as the project is more complicated than previously expected.

What I have so far:
I read all files in a dir and pull out all item DEFNAMES.

What i want/need to do.

Because all custom scripts might not have a CATEGORY or SUB CATEGORY defined i need a way to organize them.

I was thinking of having multiple ways.
1) order by itemId (i.e if you have 30 custom horses all using the id i_horse_tan then they would be ordered together).
2) Parse the DEFNAME and pull common strings. (i.e if you have 30 custom horses all should have i_horse_{something} for the id. So i can order them off of the common term i_horse).
3) Order them by the File in which they exist

Another thing i need is to be able to have this browser app send commands to the UO client.

so, if you select say, i_rlemon_custom_dye_tub and hit the 'add' button, in the UO client it will write .add i_rlemon_custom_dye_tub

the rest of the crap i want to do with it i can figure out on my own. these are the big two i need input on. Mainly the second one.