I have a string such as this:
Land of gray [example]here is an example[/example] and pink.
I'm struggling to get the PHP/regex code that will return the contents of the [example]
tag into a variable...
I have a string such as this:
Land of gray [example]here is an example[/example] and pink.
I'm struggling to get the PHP/regex code that will return the contents of the [example]
tag into a variable...
I'm not a PHP expert but... this regex will work
\[example\]([^\[]*)\[
That will capture the contents in the capture group.
So your example contents should be in $matches[1] ???
ex:
<?php
$subject = "Land of gray [example]here is an example[/example] and pink.";
$pattern = '/\[example\]([^\[]*)\[/';
preg_match($pattern, $subject, $matches);
print_r($matches[1]);
?>
I didn't test the code above because I don't have PHP running on this machine but I think that would work...