PHP function to loop thru a string and replace characters for all possible combinations
<p>I am trying to write a function that will replace characters in a string with their HTML entity encoded equivalent.</p>

<p>I want it to be able to go through all the possible combinations for the given string, for example:</p>

<ul>
<li>go one-by-one</li>
<li>then combo i.e.. 2 at a time, then three at a time, till you get length at a time</li>
<li>then start in combo split, i.e.. first and last, then first and second to last</li>
<li>then first and last two, fist and second/third last</li>
</ul>

<p>So for the characters "<code>abcd</code>" it would return:</p>

<pre><code>&amp;#97;bcd
a&amp;#98;cd
ab&amp;#99;d
abc&amp;#100;
&amp;#97;&amp;#98;cd
a&amp;#98;&amp;#99;d
ab&amp;#99;&amp;#100;
&amp;#97;&amp;#98;&amp;#99;d
a&amp;#98;&amp;#99;&amp;#100;
&amp;#97;&amp;#98;&amp;#99;&amp;#100;
&amp;#97;bc&amp;#100;
&amp;#97;b&amp;#99;d
</code></pre>

<p>etc.......... so on and so forth till there are no other combinations</p>

<p>Any ideas, or has anyone seen a function somewhere I could modify for this purpose?</p>
