I want a regex that will look at a string like this, get the "card" value from each of these comment blocks and also, TRUE if there is a "disabled":true or "hide":true mark (false otherwise) and return an array of the matches and their status. Here's an example of a string:
<!-- wp:genesis-custom-blocks/blockname {
"card":"card name 1",
"boxes":"multiple boxes",
"selected":false,
"hide":true} /-->
more content
<!-- wp:genesis-custom-blocks/blockname {
"card":"card name 2",
"boxes":"multiple boxes",
"selected":false,
"hide":true} /-->
<div>tags, etc</div>
<!-- wp:genesis-custom-blocks/blockname2 {
"card":"card name 4",
"boxes":"multiple boxes",
"selected":false,
"hide":true} /-->
<!-- wp:genesis-custom-blocks/blockname10 {
"selected":false} /-->
<!-- wp:genesis-custom-blocks/blockname2 {
"card":"card name 6",
"selected":false} /-->
other content
<!-- wp:genesis-custom-blocks/blockname2 {
"card":"card name 5",
"boxes":"multiple boxes",
"selected":false,
"disabled":true} /-->
<!-- wp:genesis-custom-blocks/blockname2 {
"card":"card name 5",
"boxes":"multiple boxes",
"selected":false} /-->
so for example for the string above I'd want:
[
["card name 1", true],
["card name 2", true],
["card name 4", true],
["card name 6", false],
["card name 5", true],
["card name 5", false]
]
I used:
preg_match_all('/"card":"(.*?)"/m', $content, $matches);
Which gets the cards values, but not the other information. What's the best way to do this? I know it will use some version of [hide|disabled]. "card" will always be the first value in these blocks, if that makes a difference.
wp:genesis-custom-blocks/blocknamelooks like JSON. So I suggest you extract the comment block contents, remove that word from the beginning, and usejson_decode()to parse it.