Source:
[display = "home"] html code [/display] [display = "category"] html code [/display] [display = "home"] html code [/display] Tell me how to write a regular expression so that the shortcode for example [display = "home"]...[/display] replaced with void. The main thing is that it would be replaced in turn. That is, the regular expression should find the beginning of [display = "..."]... and the first one found [/display] , not the last. I tried to describe clearly.
I do this in a loop, but the result is bad:
$pattern = str_replace(["\"", "[", "]", " ", "/"], ["\\\"", "\[", "\]", "\s+", "\/"], $display[1][$key]); $pattern2 = str_replace(["\"", "[", "]", " ", "/"], ["\\\"", "\[", "\]", "\s+", "\/"], $display[4][$key]); $result = preg_replace('/'.$pattern.'(.+?)'.$pattern2.'/is', "", $result); Where \[display = \"home\"\] falls into $pattern2 , \[\/display\] falls into $pattern2 but in the end the result is not what is expected.
/\[display\s+=\s+\"category\"\]([^[]+)\[\/display\]/UI have everything normal, but on the main page, when = home , vylazit it[display = "category"], it is difficult to describe in words. - Vladimir