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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:37:20+00:00 2026-05-31T02:37:20+00:00

I need help with the PHP code for the following: Get the text between

  • 0

I need help with the PHP code for the following:

Get the text between each occurrence the BBCode tags [code] and [/code] in a given string so I can then replace the spaces ‘ ‘ with the nbsp character.

Long story short, I can’t use CSS or DOM to do this, I need to do this on the server.

#[code](.*?)[/code]# seems to only work if there are no breaks (or newlines) between the starting and ending tags…. 🙁

  • 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-31T02:37:22+00:00Added an answer on May 31, 2026 at 2:37 am

    I think you’re searching for something like this

    <?php
    preg_match_all("/\[code\](.*?)\[\/code\]/ism", $search, $match);
    

    hover, I’d suggest you to use BBcode parsers instead


    To replace all spaces with &nbsp;, simply use preg_replace_callback

    <?php
    $text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism", function($match) {
         return str_replace(" ", "&nbsp;", $match[1]);
    }, $search);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really need help with using namespaces. How do I get the following code
I need help to use jConfirm with this existing code (php & Jquery &
i need help with disk_total_space function.. i have this on my code <?php $sql=select
Hi I need some help with the following scenario in php. I have a
I need some help with the following code... How do I create the array
I need help with the following piece of code, I would like to see
I need help rewriting online.php to -> /users/online and profile.php?id=3426 to -> /users/3426 and
I need help finishing this statement. It is frustrating that two of the PHP
I am newbee with PHP and MySQL and need help... I have two tables
Hey, I need help isolating part of a url in PHP. say I have

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.