-3

How would I remove the spaces between these two "words"

Input:

[/TD] [TD="align: left"]

Output:

[/TD][TD="align: left"]

All I know is it needs regex but i don't know anything about it.

admdrew
  • 3,790
  • 4
  • 27
  • 39
Shivam Paw
  • 49
  • 1
  • 2
  • 7
  • Is this a php string? like `"[/TD][TD=\"align: left\"]"` – Jay Nov 11 '14 at 19:36
  • 1
    If there's only a single space, why not simply use `$string = str_replace('] [', '', $string);` – Mark Baker Nov 11 '14 at 19:36
  • ? I'm trying to get rid of the space between the string. The string is bbcode. The input is exactly what it is and the output I posted is exactly what I need it to be. – Shivam Paw Nov 11 '14 at 19:37
  • It was downvoted because the question is a "how to do this?" type question. Many folks, including myself, don't feel this question format is optimal for SO. – Frank V Nov 11 '14 at 19:56
  • Ok. Please downvote: http://stackoverflow.com/questions/4514853/how-to-remove-space-blank-between-any-two-words-using-regexkitlite?rq=1 http://stackoverflow.com/questions/6079341/remove-space-spaces-between-two-words?rq=1 http://stackoverflow.com/questions/26836856/remove-two-or-more-empty-between-space-in-word?rq=1 http://stackoverflow.com/questions/24570744/remove-extra-spaces-but-not-space-between-two-words?rq=1 – Shivam Paw Nov 11 '14 at 20:00
  • @ShivamPaw It's funny because the first two questions you linked were historical questions with pending close votes about to get closed, and the last two was actually clear and useful, while the last question you linked actually showed effort, where yours doesn't include any of that. – Unihedron Nov 13 '14 at 19:26

3 Answers3

1

The easiest way would just be to remove any spaces between ] and [, if that words for you.

$string = '[/TD] [TD="align: left"]';
$string = preg_replace('/\]\s+\[/', '][', $string);
Sam
  • 20,096
  • 2
  • 45
  • 71
  • It appears I am going to need to keep the rest of it with spaces, only those specific strings should have the space removed. – Shivam Paw Nov 11 '14 at 19:47
0

If it is only this string you want to alter, a simple str_replace will do the job for you...

$string = '[/TD] [TD="align: left"]';

echo str_replace('] [','][',$string);

or to save to a new variable

$stringnowhite = str_replace('] [','][',$string);
baao
  • 71,625
  • 17
  • 143
  • 203
0

try this:

$string = '[/TD] [TD="align: left"]';
$string = preg_replace('/\]\s*\[/', '][', $string);
Ahosan Karim Asik
  • 3,219
  • 1
  • 18
  • 27