title: Modifying array to make <ul> lists
body: <p>I understand the title is vague, but I need help with this issue. I just can't seem to wrap my head around it.</p>
  
  <p>Basically, I have a textarea where users insert their string/text like this:</p>
  
  <pre><code>Blah blah blah blah blah this is random text whatever it could be blah blah
  
  * Un-ordered list item
  * Un-ordered list item
  
  Blah blah blah and here is some more random text because blah blah blah
  
  * Un-ordered list item
  * Un-ordered list item
  </code></pre>
  
  <p>As you can see, users can create a list by adding a <code>*</code> character that a PHP script just modify to generate the appropriate list tags.</p>
  
  <p>What I have so far is this:</p>
  
  <pre><code>$text = array();
  $c = 0;
  foreach($lines as $line) {
      if(strpos($line, "*") !== FALSE) {
          if($c == 0) {
              $text[] = "&lt;ul&gt;";
          }    
          $text[] = "&lt;li&gt;" . trim(str_replace(array("*", "\n"), '', $line)) . "&lt;/li&gt;";
          $c++;
      } else {
          $c = 0;
          $text[] = $line;
      }
  }
  </code></pre>
  
  <p>Which would return something like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Blah blah blah blah blah this is random text whatever it could be blah blah
      [1] =&gt;     
      [2] =&gt; &lt;ul&gt;
      [3] =&gt; &lt;li&gt;Un-ordered list item&lt;/li&gt;
      [4] =&gt; &lt;li&gt;Un-ordered list item&lt;/li&gt;
      [5] =&gt;     
      [6] =&gt;     Blah blah blah and here is some more random text because blah blah blah
      [7] =&gt;     
      [8] =&gt; &lt;ul&gt;
      [9] =&gt; &lt;li&gt;Un-ordered list item&lt;/li&gt;
      [10] =&gt; &lt;li&gt;Un-ordered list item&lt;/li&gt;
  )
  </code></pre>
  
  <p>What I need is to be able to close that <code>&lt;ul&gt;</code> tag off after the list is done. As you can see, the user can add as many lists as they desire, so the code block needs to be flexible to accommodate that.</p>
  
  <p>Here's an example of it in action: <a href="https://eval.in/277320" rel="nofollow"><strong><code>Example</code></strong></a></p>