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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:03:26+00:00 2026-05-20T14:03:26+00:00

I need replace spaces with &nbsp; inside HTML elements. Example: <table atrr=zxzx><tr> <td>adfa a

  • 0

I need replace spaces with &nbsp; inside HTML elements.
Example:

<table atrr="zxzx"><tr>
<td>adfa a   adfadfaf></td><td><br /> dfa  dfa</td>
</tr></table>

should become

<table atrr="zxzx"><tr>
<td>adfa&nbsp;a&nbsp;&nbsp;&nbsp;adfadfaf></td><td><br />&nbsp;dfa&nbsp;&nbsp;dfa</td>
</tr></table>
  • 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-20T14:03:27+00:00Added an answer on May 20, 2026 at 2:03 pm

    use regex to catch data between tags

    (?:<\/?\w+)(?:\s+\w+(?:\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+)?)+\s*|\s*)\/?>([^<]*)?
    

    then replace ' ' with '&nbsp;'

    also to catch before and after html :

    ^([^<>]*)<?
    
    >([^<>]*)$
    

    Edit:
    here you go….

    <?php
    $data="dasdad asd a  <table atrr=\"zxzx\"><tr><td>adfa a   adfadfaf></td><td><br /> dfa  dfa</td></tr></table>  asdasd s ";
    $exp="/((?:<\\/?\\w+)(?:\\s+\\w+(?:\\s*=\\s*(?:\\\".*?\\\"|'.*?'|[^'\\\">\\s]+)?)+\\s*|\\s*)\\/?>)([^<]*)?/";
    
    $ex1="/^([^<>]*)(<?)/i";
    $ex2="/(>)([^<>]*)$/i";
    
    $data = preg_replace_callback($exp, function ($matches) {
        return $matches[1] . str_replace(" ", "&nbsp;", $matches[2]);
    }, $data);
    $data = preg_replace_callback($ex1, function ($matches) {
        return str_replace(" ", "&nbsp;", $matches[1]) . $matches[2];
    }, $data);
    $data = preg_replace_callback($ex2, function ($matches) {
        return $matches[1] . str_replace(" ", "&nbsp;", $matches[2]);
    }, $data);
    
    echo $data;
    ?>
    

    it works… slightly modified but it would work without modifications (but i dont think youd understand the code 😉 )

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

Sidebar

Related Questions

I need to replace all & symbols with &#38 in my text file but
I use some telerik report to print some report. I need to use Telerik.Reporting.TextBox
I want to use this but need a solution for this.. NSString *googleAddress =
I have a file that I need to reformat and remove extra blank lines.
I'm trying to write some Perl to convert some HTML-based text over to MediaWiki
I need to do some global changes to a number of spreadsheets and I
I'm working on a UserViewModel, and I'm wondering if it's appropriate to do minor
Working with multiple language sites in Sitecore 6.2 I'd like to be able to
I have File Like Sample.bak and when I compress it to be Sample.zip I
When I run the decorate_keyword() function below, I'm getting two errors that I'm trying

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.