remove square brackets from string php code example

Example 1: remove square brackets from string php

preg_match_all('/\[\[([^\]]+)\]\]/', $yourText, $matches);
foreach($matches as $link) {
   echo $link[1];
}

Example 2: remove square brackets from string php

$output = preg_replace( '/\[\[(\w+)\[\]/' , '$1' , $string );

Example 3: remove square brackets from string php

str_replace( array('[',']') , ''  , $string )

Example 4: remove square brackets from string php

$repl = str_replace(array('[[', ']]'), '', '[[link_to_page]]');// "link_to_page"

Example 5: remove square brackets from string php

$repl = preg_replace('/(\[|\]){2}/', '', '[[link_to_page]]');// "link_to_page"

Example 6: remove square brackets from string php

$string = str_replace(array('[[',']]'),'',$string);

Tags:

Misc Example