[Solved] For every new text line separate, put that line into a div tag [closed]


Step by step breaking the problem down into stages:

1) What you need is to break the text file up into “rows”. Because different systems use different seperators for “rows” of text; you should use the PHP_EOL special constant.

2) Once split into rows, you then need to wrap these rows in the desired HTML formatting

3) and then recombine them into the output.

so:

$parts = explode(PHP_EOL,$data);
foreach($data as $row){
     $row = "<div class="instructionStyling">".$row."</div>\n";
}
unset($row);
$output = "<div class="instructionStyling">".implode(PHP_EOL,$parts)."</div>";  

Perform this step
Then do this step
Lastly, do this step

Becomes:

<div class="instructionStyling">Perform this step</div>
<div class="instructionStyling">Then do this step</div>
<div class="instructionStyling">Lastly, do this step</div>

Shorter Version:

$output = preg_replace("/\n+/i","</li><li>",$data);
$output = "<ul><li>".substr_replace($data,"</ul>",-4,4);
<ul><li>Perform this step</li>
<li>Then do this step</li>
<li>Lastly, do this step</li></ul>

  • Using style sheets and li/ul is preferential.
  • processing the contents of the string means you do also need to wrap the finished string in HTML (divs or uls, etc.)
  • \n is a drop in replacement for PHP_EOL for clarity but PHP_EOL is recommended throughout

solved For every new text line separate, put that line into a div tag [closed]