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

  • SEARCH
  • Home
  • 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 8125533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:51:06+00:00 2026-06-06T06:51:06+00:00

Suppose I have a Markdown string: * Bullet has *bold [code]*test[/code] part*. *Another\nbold* item.

  • 0

Suppose I have a Markdown string:

* Bullet has *bold [code]*test[/code] part*. *Another\nbold* item.

And I want to convert it to BBCode like:

* Bullet has [b]bold [code]*test[/code] part[/b]. [b]Another\nbold[/b] item.

…and, as you can tell above, preserve what was inside [code]. How would I accomplish this?

BACKGROUND

See, I’m trying to tweak a FluxBB forum. It permits BBCode by default. However, I wanted to also permit a small subset of Markdown for noobs, such as bolding and italics. At least for bolding, this is possible with a statement like:

$out = preg_replace('/\*(\S.*?\S)\*/s','[b]$1[/b]',$in);

…but has a problem with the *test part, where it wants to translate that too.

  • 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-06-06T06:51:07+00:00Added an answer on June 6, 2026 at 6:51 am

    The following code seems to work. I preserve using a preg_replace_callback() and bin2hex(), and then unhex via pack() through another preg_replace_callback().

    $a = "* Bullet\n* Bullet has *bold [code]*test[/code] part*. *Another\nbold* item.";
    echo $a;
    echo "\n";
    // PRESERVE CODE BLOCK
    $a = preg_replace_callback('/\[code\](.*?)\[\/code\]/s',create_function('$a','return "[code]" . bin2hex($a[1]) . "[/code]";'),$a);
    // HANDLE MARKDOWN FOR BOLD
    $a = preg_replace('/\*(\S.*?\S)\*/s','[b]$1[/b]',$a);
    // RESTORE CODE BLOCK
    $a = preg_replace_callback('/\[code\](.*?)\[\/code\]/s',create_function('$a','return "[code]" . pack("H*",$a[1]) . "[/code]";'),$a);
    echo $a;
    echo "\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

suppose we have this next sample code: while(some condition){ lock1.lock(); . . } the
Suppose I have a superclass Item and a subclass MovingItem. If I create an
Suppose I have the following table: PERSON : ID INT NAME STRING LASTNAME STRING
Suppose we have a numbered circle. We want to go from point A to
I am trying to use Pagedown to convert some markdown into HTML. I have
Suppose I have a file test.c containing the following: // line 1 // line
Suppose i have a cookie set in first.com say user. Now i want to
Suppose I have a FruitDetector class which takes in a string and returns the
Suppose I have the following HTML snippet: <input type=text id=myinput /> Now I want
Suppose I have this code: -(SomeOtherType*) getMyObject { SomeType someObject = [[SomeType alloc] init];

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.