php - Strange linebreak characters showing up in my view -
i using codeigniter generate html table insertion template view. how insert linebreaks in generated html code , experimentation, have been able change code to:
$string='<table id="mydatatable" class="table table-bordered table-striped" style="clear: both">\n <tbody>\n'; foreach ($array $key => $value) { $string=$string."\t\n<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>\n'; $string=$string.$element; } $string=$string.'</tbody>\n</table>';
i inject produced html string ci view looks like:
<!doctype html> <html lang="en"> <head> <base href="<?=base_url();?>"> <meta charset="utf-8"> <meta name="author" content="vitaliy potapov"> <meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="cache-control" content="no-cache" /> <link href="css/bootstrap.css" rel="stylesheet"> <link href="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.4.5/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet"/> </head> <body> <?=$html_string;?> <script src='js/jquery.js'></script> <script src="js/bootstrap.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.4.5/bootstrap-editable/js/bootstrap-editable.min.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function() { $('#mydatatable').editable(); $.fn.editable.defaults.mode = 'inline'; }); </script> </body> </html>
i getting expected table, nbut reason see bunch of generated new line charachters before table when @ generated html.
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n
why happening , how can fix this?
escaped characters not interpolated when using single quotes. fix either remove \n string or change code this:
<?php $string='<table id="mydatatable" class="table table-bordered table-striped" style="clear: both">'."\n".' <tbody>'."\n"; foreach ($array $key => $value) { $string=$string."\t\n<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>'."\n"; $string=$string.$element; } $string=$string."</tbody>\n</table>";
Comments
Post a Comment