0

Here is my code:

$tags_specified_pattern = "/\[(.+?)\]/";
preg_match_all($tags_specified_pattern, $q, $matches);
if ( count($matches[1]) ){
    I need to remove all matched parts form $q
}

Here is an example:

$q = "This is [tag1] tag1 and this is [tag2] tag2";

And this is the expected result:

This is tag1 and this is tag2

Any idea how can I do that?

Martin AJ
  • 6,261
  • 8
  • 53
  • 111

1 Answers1

0

You can use preg_replace

<?php
$pattern = '/\\[(.+?)\\]/';
$replacement = '';
$subject = 'This is [tag1] tag1 and this is [tag2] tag2';
echo preg_replace($pattern, $replacement, $subject, -1 );
?>
Bhumi Shah
  • 9,323
  • 7
  • 63
  • 104