Alex
Alex

Reputation: 6645

Search string for tag text

How can I search a string for a tag inside [ ] with parameters? So, for example, my string may have in it somewhere:

[tag id='1,2,5']

The numbers in the id parameter could be anything. I want to search to see if the tag is present and if so extract the numbers in the id paramter.

Upvotes: 0

Views: 52

Answers (1)

zerkms
zerkms

Reputation: 254886

preg_match_all("~\[tag\s+id='([^']+)'\]~", $str, $matches);
var_dump($matches);

http://ideone.com/6b9JX

Upvotes: 1

Related Questions