phpregexplaceholdertext-extractioncurly-braces

Extract all words double wrapped in curly braces


I have a string that is formatted like the following:

... {{word1}} {{word2}} .... etc

I need to extract all the words, located inside the '{{' and '}}' tags.

What is the most efficient way to retrieve the words from the string in PHP?


Solution

  • Using pattern /\{\{(\w+)\}\}/ you can extract all the words

    preg_match_all("/\{\{(\w+)\}\}/", $str, $matches);
    print_r($matches[1]);
    

    http://ideone.com/pyB4D