i have couple of form fields should respect spaces in text input, i.e. convert text blocks paragraphs <p> ... </p>
.
furthermore, lines begin ** should converted list items <li> ... </li>
of unordered list <ul> ... </ul>
.
$textareas = array( 'form_field_1', 'form_field_2', 'form_field_3' ); foreach($textareas $name) { $text = $data[$name]; $text = "<p>". str_replace("\n\n", "</p><p>", $text) . "</p>"; $text = str_replace("\n", "<br />", $text); $text = "<ul>". str_replace("**", "<li>", $text) . "</li></ul>"; $data[$name] = $text; }
while paragraph conversion works, having trouble list items. current code surround every paragraph in ul tags. however, should surround list items.
would appreciate ideas how fix this.
Comments
Post a Comment