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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:39:47+00:00 2026-05-29T19:39:47+00:00

Could I please get some help with coverting some PHP code to jQuery/JavaScript? What

  • 0

Could I please get some help with coverting some PHP code to jQuery/JavaScript? What I want is a simple BBCode to HTML converter.

Here is the PHP code. I want to achieve the same thing using jQuery/JavaScript.

$str = htmlentities($str);

// The array of regex patterns to look for
$format_search =  array(
    '#\[b\](.*?)\[/b\]#is',
    '#\[i\](.*?)\[/i\]#is',
    '#\[u\](.*?)\[/u\]#is',
);

// The matching array of strings to replace matches with
$format_replace = array(
    '<strong>$1</strong>',
    '<em>$1</em>',
    '<span style="text-decoration: underline;">$1</span>',
);

// Perform the actual conversion
$str = preg_replace($format_search, $format_replace, $str);

Thanks for your help!

  • 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-29T19:39:48+00:00Added an answer on May 29, 2026 at 7:39 pm

    Looks ALMOST like you just need to change # to / and is to ig but I also had to change /b to \/b

    Live Demo

    $str = 'this is a [b]bolded[/b] and [i]italic[/i] string';
    
    // The array of regex patterns to look for
    $format_search =  [
        /\[b\](.*?)\[\/b\]/ig,
        /\[i\](.*?)\[\/i\]/ig,
        /\[u\](.*?)\[\/u\]/ig
    ]; // note: NO comma after the last entry
    
    // The matching array of strings to replace matches with
    $format_replace = [
        '<strong>$1</strong>',
        '<em>$1</em>',
        '<span style="text-decoration: underline;">$1</span>'
    ];
    
    // Perform the actual conversion
    for (var i =0;i<$format_search.length;i++) {
      $str = $str.replace($format_search[i], $format_replace[i]);
    }
    alert($str)
    

    Other Live Demo

    function boldFunc(str, p1, offset, s) {
      return '<strong>'+encodeURIComponent(p1)+'</strong>'
    }
    
    function italicFunc(str, p1, offset, s) {
      return '<em>'+encodeURIComponent(p1)+'</em>'
    }
    
    function underlinedFunc(str, p1, offset, s) {
      return '<span class="un">'+encodeURIComponent(p1)+'</span>'
    }
    
    
    $str = 'this is a [b]bölded[/b], [i]itälic[/i] and [u]ünderlined[/u] [i]strïng[/i]';
    
    // The array of regex patterns to look for
    $format_search =  [
        /\[b\](.*?)\[\/b\]/ig,
        /\[i\](.*?)\[\/i\]/ig,
        /\[u\](.*?)\[\/u\]/ig
    ]; // NOTE: No comma after the last entry
    
    // The matching array of strings to replace matches with
    $format_replace = [
        boldFunc,
        italicFunc,
        underlinedFunc
    ];
    
    // Perform the actual conversion
    for (var i =0;i<$format_search.length;i++) {
      $str = $str.replace($format_search[i], $format_replace[i]);
    }
    document.getElementById('output').innerHTML=$str;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could I get some help creating this query please? Users book product video slots
Could somebody please help me get Clang up and running? (I don't have 3.2)
Could you please help me to get image upload working on a view with
Could someone please help explain why I can't get this to work? I properly
Could anyone please explain the following line of code, found on http://docs.openttd.org/ai__cargo_8cpp_source.html return (AICargo::TownEffect)::CargoSpec::Get(cargo_type)->town_effect;
I need some help with this please I can't get a handle on it.
I'd like some help with the following jQuery code if possible... $(document).ready(function() { $('table.sortable').each(function()
I am pretty new to php and could sure use some help understanding how
Could someone please demystify interfaces for me or point me to some good examples?
Could you please show me the C# Equivalent of this VB.NET code: Public Partial

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.