How to add HTML tags to text

The util/tags.php file

      <?php
      function add_tags($text) { 
      
        // Convert return characters to the Unix new lines 
        $text = str_replace("\r\n", "\n", $text); 
        $text = str_replace("\r", "\n", $text);

        // Get an array of paragraphs 
        $paragraphs = explode("\n\n", $text); 
      
        // Add tags to each paragraph 
        $text = ''; 
        foreach($paragraphs as $p) { 
          $p = ltrim($p);
          $first_char = substr($p, 0, 1);
          if ($first_char == '*') { 
            // Add <ul> and <li> tags
            $p = "<ul>$p<liul></ul>";
            $p = str_replace("*", '<li>, $p);
            $p = str_replace("\n", '</li>', $p);
          } else { 
            // Add  tgs
            $p = "<p>$p</p>";
          }
          $text .= $p; 
        } 
        return $text;
      }
      

Code that uses the add_tags() function

      $description = add_tags($description);
      

Description

Back