Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4082610
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:12:32+00:00 2026-05-20T18:12:32+00:00

The question is extremely easy, but the solution might not. Let’s say this is

  • 0

The question is extremely easy, but the solution might not.

Let’s say this is my text input inside a variable called $description:

<p>
text text text
text text text
</p>
<ul>
text text
text text
text text
</ul>
<p>
text text text
text text text
</p>

I believe it’s already obvious what I need to do. I need to locate all <ul></ul> tags inside my string and add <li></li> tags for each entry inside, under these conditions:

  • I don’t know how many <ul></ul> tags there might be in total, the function should find all of them
  • All list-entries inside each <ul></ul> WILL be separated by enter (\r\n)

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:12:33+00:00Added an answer on May 20, 2026 at 6:12 pm

    This will do the job:

      function addLI ($in) {
         $in = str_replace("\r\n", "\n", $in);
         $lines = explode("\n", $in);
         $out = "";
         $ul = false;
         foreach($lines as $line) {
            if ($ul == false) {
               if (stripos($line, "<ul>") !== false) {
                  $ul = true;
               }
            }
            else {
               if (stripos($line, "</ul>") !== false) {
                  $ul = false;
               }
               else {
                  $line = "<li>" . $line . "</li>";
               }
            }
            $out .= $line . "\n";
         }
         return $out;
      }
    

    Edit: first edition worked only with “\n” – now it works with “\n” and “\r\n”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question is probably extremely easy to resolve, but I need to resolve it
I know this same question was asked for Entity Framework 1, but now that
Edit: This is not a conflict on the theoretical level but a conflict on
Right now I'm making an extremely simple website- about 5 pages. Question is if
Just to keep things interesting and close my final open question, the solution that
NOTE : Right before posting this question it occurred to me there's a better
This is a 2 part question. 1) Is there some sort of program that
Question as stated in the title.
Question is pretty self explanitory. I want to do a simple find and replace,
Question Alright, I'm confused by all the buzzwords and press release bingo going on.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.