使用php更改<li>元素的位置

I have few lists in my webpage like this for example it is in a DIV

<div id="list">

<li id = 1> 1 </li>
<li id = 4> 4 </li>
<li id = 5> 5 </li>
<li id = 2> 2 </li>
<li id = 3> 3 </li>

What i want to do is using html parser change the order to like this

<div id="list">

<li id = 1> 1 </li>
<li id = 2> 2 </li>
<li id = 3> 3 </li>
<li id = 4> 4 </li>
<li id = 5> 5 </li>

Is this even possible?

EDIT:

Can anyone give me an idea of what the code can be?

Use http://php.net/manual/ru/class.domdocument.php class to manipulate with XML\HTML