Is it possible to have a PHP regex expression that extracts the content from the first ] to the last [?
For example if I had the following string:
$string = [shortcode]You write a shortcode by using ([])[/shortcode]
I would want to extract:
You write a shortcode by using brackets ([])
and store it in a variable. The content to be extracted could be anything. Thanks in advance.
$content = [shortcode]You write a shortcode by using ([])[/shortcode] $start = strpos($content, ']'); $start = $start + 1; $end = strrpos($content, '['); $dif = $end - $start; $content = substr($content, $start, $dif); echo $content; //output: You write a shortcode by using ([])I think that will do the trick.