What potential issues can arise when using preg_match in PHP to extract content between specific markers in a string?
One potential issue when using preg_match in PHP to extract content between specific markers in a string is that the regular expression may not capture the desired content accurately if the markers are not unique or if there are nested markers. To solve this, you can use a non-greedy quantifier in the regular expression to ensure that it captures the content between the closest pair of markers.
$string = "This is a [sample] string with [multiple] markers";
$pattern = "/\[.*?\]/";
preg_match_all($pattern, $string, $matches);
print_r($matches[0]);