TheSM
TheSM

Reputation: 59

Troubles using RegEx on PHP

I have a sip.conf file that contains data like that :

#<COMPTE
[6007](template)
fullname = ggg
username = ggg
secret = nana
COMPTE>#

#<COMPTE
[6008](template)
fullname = dada
username = dada
secret = dada
COMPTE>#

I have created a method using java :

Matcher matcher = Pattern.compile("(?m)^#<COMPTE.*?COMPTE>#",Pattern.MULTILINE | Pattern.DOTALL).matcher(chaine);
 while (matcher.find()) {       
       comptes=matcher.group();                     
}

I want something like that in PHP I have tried many things but it doesn't seems to work, any help ?

Upvotes: 0

Views: 41

Answers (1)

S. Ahn
S. Ahn

Reputation: 663

I think this is what you're looking for.

$chaine = <<<EOT
#<COMPTE
[6007](template)
fullname = ggg
username = ggg
secret = nana
COMPTE>#

#<COMPTE
[6008](template)
fullname = dada
username = dada
secret = dada
COMPTE>#
EOT;

$pattern = "/COMPTE(.*?)COMPTE/sm"; // s = dotall, m = multiline
preg_match_all($pattern, $chaine, $matches);
print_r($matches);

Upvotes: 1

Related Questions