Reading part of system file contents with PHP
I have a config
file, in etc/
called 1.conf
Here is the contents..
[2-main]
exten => s,1,Macro(speech,"hi {$VAR1} how is your day going?")
exten => s,4,Macro(dial,2,555555555)
exten => s,2,Macro(speech,"lkqejqe;j")
exten => s,3,Macro(speech,"hi there")
exten => s,5,Macro(speech,"this is a test ")
exten =&g开发者_如何转开发t; s,6,Macro(speech,"testing 2")
exten => s,7,Macro(speech,"this is a test")
exten => 7,1,Goto(2-tester2,s,1)
exten => 1,1,Goto(2-aa,s,1)
[2-tester]
[2-aa]
exten => 1,1,Goto(2-main,s,1)
How can I read the content in between speech for example..
exten => s,6,Macro(speech,"testing 2")
Just get "testing 2"
from that.
Thank you in advance!
If I understand correctly, this
$text = file_get_contents('/etc/1.conf');
preg_match_all('/speech,"(.*)"/', $text, $match);
will fill the $match
array with all the text from speech lines. Specifically, $match[1]
will be an array containing just the string inside the quotes, so you can do this for convenience and readability:
$speeches = $match[1];
echo $speeches[0]; // or 1 or 2 etc.
精彩评论