I have added a custom metabox that holds string from a textarea in database. Now if I just simply echo the meta box like this:
$post_meta = get_post_meta($pid);
$answer = $post_meta["answer"][0];
echo $answer;
the html tags would be escaped and the text would appear like this:
blah blah blah <ul><li>blah blah</li><li>blah</li></ul>
As you see the html tags get escaped and they appear as string so I use php like this:
$answer = html_entity_decode($answer);
Now the html tags work as they are expected but there remains one problem. In order to get the line breaks from the database I add another line like this:
$answer = nl2br($answer);
which solves the problem with line breaks but add a new line break between each li tags.
Any idea how to resolve this? I need line breaks but at the same time would want to avoid adding a line break between li tags.
UPDATE: for the moment I added this line of php after nl2br and I got the result
$answer = preg_replace("!</li>[\s\S]{1,100}?<!", "</li><", $answer);
But I don't think this is the right way to go.