Take input from text box and parse each line into bullet list

$method1 = '<ul><li>' . implode('</li><li>', explode("\n", $method)) . '</li></ul>';

I have this code here and i am trying to parse the input so that each new line that is entered into a text box is parsed to a bullet list, but for some reason this code is only doing the first line

Example:

do this do this

turns into this inside a single variable:

<ul> <li>do this</li> <li>do this</li> </ul>

-------------Problems Reply------------

Do you mean this (I've used your variable names):

// explode
$list = explode("\n", $method);

// iterate
$method1 = "<ul>";
foreach ($list as $item) {
$method1 .= "<li>" . $item . "</li>";
}
$method1 .= "</ul>";

// output
echo $method1;

Somethimes \n doesnt really recognize as new line in php.

try this:

$method1 = '<ul><li>' . implode('</li><li>', explode("
", $method)) . '</li></ul>';

Category:php Views:0 Time:2011-11-24
Tags: php parsing

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.195 (s). 11 q(s)