php - How to convert ** into unordered list items while respecting paragraphs? -


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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -