April 13, 201313 yr Hey guys, Basically as the title. If I have a web form where someone can enter a list of items in a textarea, eg: Bread Cheese Wine Figs Is there a way I can in my php make the output of that list a numbered list? 1. Bread 2. Cheese 3. Wine 4. Figs I'm outputting the complete form data on the same page in plaintext and this is basically to save the user having to type the numbers themselves. Is it possible? Edited April 13, 201313 yr by Killer
April 13, 201313 yr $bullets = preg_split("/\\r?\\n/", $string); // $string = $_POST['your_input'] echo "<ol>"; foreach ($bullets as $bullet) { echo "<li>" . htmlentities($bullet) . "</li>"; } echo "</ol>"; Edited April 13, 201313 yr by andy9l
April 14, 201313 yr Author Perfect, thank you. Actually there is one issue I hadn't consindered. The output text of the form is designed to be copied by the user and obviously with an OL the numbers aren't copied when you copy into a plain text editor. How could I get around that? I need the numbers to be copied as well somehow. Edited April 14, 201313 yr by Killer
Create an account or sign in to comment