I have an array which is coming from db. Array has strings which is delimited by <br>
. So I want to explode them and convert it to a
<ul>
<li>...</li>
</ul>
structure using a function (listIt($list)
):
function listIt($list)
{
$list = mb_convert_case($list, MB_CASE_TITLE, 'UTF-8');
$text = explode('<br>', $list);
$menu = '<ul>';
foreach ($text as $li)
{
$menu .= '<li>' . $li . '</li>';
}
return $menu . '</ul>';
}
My Array (rawMenu
) is the following:
array (size=5)
0 => string 'Banana<br>Cheese<br>Egg<br>Salad<br>Water<br>Juice<br>Coffee' (length=62)
1 => string 'Soup<br>Potato<br>Chicken<br>Fish<br>Juice<br>Wine<br>Salad' (length=61)
2 => string 'Banana<br>Cheese<br>Egg<br>Salad<br>Water<br>Juice<br>Coffee' (length=62)
3 => string 'Soup<br>Potato<br>Chicken<br>Fish<br>Juice<br>Wine<br>Salad' (length=61)
4 => string 'Banana<br>Cheese<br>Egg<br>Salad<br>Water<br>Juice<br>Coffee' (length=62)
The problem is string which I pass to listIt($rawMenu[4])
function returns:
<ul>
<li>Banana<br>Cheese<br>Egg<br>Salad<br>Water<br>Juice<br>Coffee</li>
</ul>