Jump to content

BBCode list with newlines


Dragen

Recommended Posts

Hi,

I'm currently using my own BBCode to create bullet point liists (<ul><li>).

I've got two preg replace calls to turn the code into the HTML lists:

(\[list\](<br />)*(.+?)\[/list\](<br />)*)s

which finds the

[list][/list]

block and replaces it with <ul></ul>

 

(\[\*\](.+?)(<br />)+)

which finds

[*]

and the following text and creates the <li></li>

 

For example, the following text:

[list]
[*]list item 1
[*]list item 2
[*]list item 3
[/list]

would become:

<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
</ul>

 

 

The problem I've got is that I need to be able to capture any newline characters within the BBCode

[*]

section.

At the moment, if I try to add a newline in the list it doesn't create the <li></li> properly, it adds the </li> at the newline, when I only want the </li> added on the last newline character:

[list]
[*]item
list 1
[/list]

currently creates:

<ul>
<li>item</li>
list 1
</ul>

When it should be:

<ul>
<li>item<br />
list 1</li>
</ul>

 

 

I've got another part which changes all newlines to <br />, I just need the list part to ignore all, but the last newline in the

[*]

section.

I need to somehow change this regex to do this:

(\[\*\](.+?)(<br />)+)

I've been working on it for ages and it's just evaded me, any help would be brilliant!!

Link to comment
https://forums.phpfreaks.com/topic/149665-bbcode-list-with-newlines/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.