0

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 ?

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it worked when I changed it to : $pattern = "/COMPTE(.*?)COMPTE/sm"; I accecpt your answer, if you can edit it as I mentioned so other people find out the right answer ;)
I made the change. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.