i'm working wordpress , trying turn paragraphs ordered list , it's working perfectly. code:
$list_items1 = explode("<p>", $bulletlist); echo '<ul>'; foreach($list_items1 $list_item) echo '<li>' . $list_item . '</li>'; echo '</ul>';
the problem is, creates empty list item @ beginning of each list, this:
<ul> <li></li> <li>list item 1</li> <li>list item 2</li> <li>list item 3</li> </ul>
how can fixed? there other solution fix that? in advance! ps: should work ordered list.
a possible solution replace occurrences of p>
li>
.
$list_items = str_replace('p>', 'li>', $bulletlist); echo '<ul>' . $list_items . '</ul>';
the problem approach explode('<p>', '<p>a</p><p>b</p><p>c</p>')
results in following array.
array(4) { [0]=> string(0) "" [1]=> string(5) "a</p>" [2]=> string(5) "b</p>" [3]=> string(5) "c</p>" }
the first element empty because there nothing on left of first <p>
tag. others have suggested there workarounds ignoring first element, still have deal leftover </p>
tags, mess html.
Comments
Post a Comment