title: How can i use PHP explode to create HTML table from text file with a space in between each word
body: <p>I have a text file with 3 columns split with spaces that contains the following:</p>
  
  <pre><code>word1 word2 word3
  word4 word5 word6
  word7 word8 word9
  </code></pre>
  
  <p>I have the following PHP that turns my text file into a table, however it puts each line of the text file into one table cell, i want it to put each word into a table cell.</p>
  
  <pre><code>&lt;?php
           $tdcount = 1; $numtd = 3; // number of cells per row
           $str = "&lt;table class=\"table table-hover table-striped\"&gt;
                                           &lt;thead&gt;
                                           &lt;th&gt;colum1&lt;/th&gt;
                                           &lt;th&gt;colum2&lt;/th&gt;
                                           &lt;th&gt;colum3&lt;/th&gt;
                                           &lt;/thead&gt;
                                           &lt;tbody&gt;
  
       ";
           $f = fopen("/text.txt", "r");
           if ( $f === FALSE ) {
           exit;
                  }
           while (!feof($f)) {
               $arrM = explode(",",fgets($f));
               $row = current ( $arrM );
               if ($tdcount == 1)
                   $str .= "&lt;tr&gt;"; $str .= "&lt;td&gt;$row &lt;/td&gt;";
               if ($tdcount == $numtd) {
                   $str .= "&lt;/tr&gt;";
                   $tdcount = 1;
               } else {
                   $tdcount++;
               }
           }
           if ($tdcount!= 1) {
               while ($tdcount &lt;= $numtd) {
                   $str .= "&lt;td&gt;&amp;nbsp;&lt;/td&gt;"; $tdcount++;
               } $str .= "&lt;/tr&gt;";
           }
           $str .= "&lt;/tbody&gt;&lt;/table&gt;";
           echo $str;
           exit;
  
  ?&gt;
  </code></pre>
  
  <p>I have tried playing with  explode line by changing the , to a space however it doesn't work:</p>
  
  <pre><code>$arrM = explode(" ",fgets($f));
  </code></pre>
  
  <p>How can i do this?</p>