Simply put, I need to extract all strings enclosed in curly braces from a chunk of text, as in
Here is a {tag}, but here {tag_2} as well, and then again …{tag_3}… here but with some trash around it.
I would like to get an array of tag, tag_2 and tag_3.
Tags can only have word characters.
I tried this:
$tags = array();
preg_match_all("/\{\w+\}/s", $data['text'], $tags);
The tags array is returned empty if run on the above fragment of text.
Edit:
I apologize for the nuisance everyone, it turns out I messed up later on. I was catching the tags via $tags, instead of $tags[0], and thus my merged array was always empty.
It works fine:
produces:
Your
$data['text']is probably empty.Tested with Ideone.