Hello Community,
I was wanting to make a bbcode system using regex but the one I'm having a problem with is the list (<ol> and <ul>) but for some reason it isn't working this is the code I'm using:

    function convertBBCode($input) {
      $bbCode = array(

      $htmlCode = array(
          "<a href=\"\\1\" target=\"_blank\">\\1</a>",
          "<a href=\"\\2\" target=\"_blank\">\\1</a>",
          "<img src=\"\\1\">",

      return preg_replace($bbCode, $htmlCode, $input);
    echo convertBBCode($_POST['inputText']);

<form action="index.php" method="POST">
    <textarea name="inputText">
    <input type="submit"/>

Try the code out and you'll see what's happening, which is just inserting the [li]Hello[/li] and not the [ol] and [/ol] I've looked online for any examples on why it's happening but I'm thinking it could have something with the regex line thinking it isn't reading the newline (\n).


"/\[ol\](.*?)\[\/ol\]/s", // s is for "dot matches line breaks"

Thank you but not a big deal but is there a way to make it so it doesn't insert newlines because I'm getting what I wanted but between each list item there is a linebreak. So is there a way to remove the <br>?

A str_replace() perhaps?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.