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 5951663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:34:11+00:00 2026-05-22T17:34:11+00:00

I want to convert following text into list items * Item 1 * Item

  • 0

I want to convert following text into list items

* Item 1
* Item 2

- item 1
- item 2

to

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
</ul>

I have made following regex which is not good enough for this

$text = preg_replace('#(*\s[*.]\s*)#','<li>$0</li>', $text); 

but that does not work. I am not good at making RE.

I am making question more clear here.

A text may contain bullets or may not and I cant loop through the file as atno suggested.

Here are the samples

* HTML *SEO * Javascript * PHP

- HTML
- SEO
-Javascript
-PHP

-HTML - SEO -Javascript -PHP
  • 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-22T17:34:12+00:00Added an answer on May 22, 2026 at 5:34 pm

    A little nasty to do with regular expressions, but here you go:

    <?php
    $text = <<<TEXT
    * HTML *SEO * Javascript * PHP
    
    - HTML
    - SEO
    -Javascript
    -PHP
    
    -HTML - SEO -Javascript -PHP
    TEXT;
    
    $text = preg_replace_callback('`([*-]\s*([^*-\r\n]+)(\r?\n)?)+`', function($m) {
        $str = '<ul>';
        $str .= preg_replace('`[*-]\s*([^*-\r\n]+)\s*`', '<li>$1</li>', $m[0]);
        $str .= '</ul>';
        return $str;
    }, $text);
    
    echo $text;
    

    I get this as output:

    *snip* clarification changes output

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

Sidebar

Related Questions

Hello I have text in following format. But I want to convert into dict.
I have the following option text that I want to put into a variable
I have the following code in Ruby. I want to convert this code into
I have the following string: 2010-04-08T12:46:43+00:00 I want to convert that to: 8th April
I have a plain text file which have the list of countries as follows.
I want to convert the following string into Date type this way Date dateToFormat
Is it possible to convert text into a number within MySQL query? I have
I want to convert a string into a byte array. (Yes) I have seen
I want to convert NSString into NSDate. So I tried following code : NSDateFormatter
I want to convert following html code into continuous string using jquery/javascript. <ul> <li>one</li>

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.