php - How to insert linebreaks in generated html code -


i using codeigniter generate html table insertion template view. unfortunately coming out long string on 1 line like:

<table id="mydatatable" class="table table-bordered table-striped" style="clear: both"><tbody><tr><td>id</td><td><a href="#" id="id" data-type="text" data-pk="2" data-url="/post" data-title="id">2</a></td></tr><tr><td>email</td><td><a href="#" id="email" data-type="text" data-pk="2" data-url="/post" data-title="email">a@b.com</a></td></tr><br><tr><td>notes</td><td><a href="#" id="notes" data-type="text" data-pk="2" data-url="/post" data-title="notes">notes go here</a></td></tr><br> ... 

i want more like:

<tr>              <td>field1</td>     <td><a href="#" id="field1" data-type="select" data-pk="1" data-value="" data-original-title="select field1"></a></td>     <td><span class="muted">select, loaded js array. custom display</span></td> </tr>  <tr>              <td>field2</td>     <td><a href="#" id="field2" data-type="select" data-pk="1" data-value="" data-original-title="select field2"></a></td>     <td><span class="muted">select, loaded js array. custom display</span></td> </tr> 

here code:

$string='<table id="mydatatable" class="table table-bordered table-striped" style="clear: both"><tbody>';  foreach ($array $key => $value) {     $string=$string."<tr><td>$key</td>";       $element='<td><a href="#" id="'.$key.'" data-type="text" data-pk="'.$rowid.'" data-url="/post" data-title="'.$key.'">'.$value.'</a>'.'</td></tr>'."<br>";     $string=$string.$element; }  $string=$string.'</tbody></table>'; 

how can fix this?

you can add newlines (\n) , tabs (\t) $string variable.

e.g.:

$string='<table id="mydatatable" class="table table-bordered table-striped" style="clear: both">\n\t<tbody>\n'; foreach ($array $key => $value) {     $string = $string."<tr>\n\t<td>$key</td>\n";       $element = '\t<td><a href="#" id="'.$key.'" data-type="text" data-pk="'             .$rowid.'" data-url="/post" data-title="'.$key.'">'.$value.'</a>'             .'</td>\n</tr>'."<br>";     $string = $string.$element; } $string=$string.'\n\t</tbody>\n</table>'; 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -