0

so i am trying to fetch news from an API, everything is working fine so far, except that i got some issues with the format.

From the API the News are in JSON format, i already got them visible on the page and it looks alright, except for <ul> and <li> items

enter image description here

When using a list, the dots will be over the text, since its closing the tags right after. I have been googling for a while and i haven't found a proper solution, using list-style didn't help.

Here is the preg_replace i use for the list items:

    /*[list]*/
    $tmpText = preg_replace('#\[list\](.*)\[/list\]#isU', '<ul>$1</ul>', $tmpText);

    /*[*]*/
    $tmpText = preg_replace('#\[[*]](.*)#isU', '<li>$1</li>', $tmpText);

And this is the output on the page i get with this:

<ul>
<li></li> Halloween content implementation
<li></li> Barber implementation and polishing
<li></li> Additional work on modular vehicles
<li></li> Finishing touches on the ATM interface
<li></li> Implementation of halloween gestures
<li></li> Final preparations for permadeath testing
<li></li> Creation and implementation of new admin commands
<li></li> Additional work on the farming system
<li></li> Bugfixing
</ul>

I am not really sure how to fix this, or how i would get the text between the tags, since its input is always different, i would appreciate some tips

Spyr0
  • 193
  • 9

1 Answers1

0

Never mind I just solved my own issue, I had a huge brain fart here.

This is the solution I thought about

/*[list]*/
$tmpText = preg_replace('#\[list\](.*)\[/list\]#isU', '<ul>$1</li></ul>', $tmpText);
/*[*]*/
$tmpText = preg_replace('#\[[*]](.*)#isU', '<li>$1', $tmpText);
Michael M.
  • 10,486
  • 9
  • 18
  • 34
Spyr0
  • 193
  • 9
  • 1
    Pro-Tip: `
  • ` are nice in HTML because the closing tags are optional. Use these semantics for your benefit. Compare: https://stackoverflow.com/a/20550925/367456
  • – hakre Oct 28 '22 at 15:39