Can you please post some test data? We do not have the credentials to use the script posted here, but if you give us the test data and show us what you want to get for output, we should be able to help. Best, ~Ray
Main Topics
Browse All TopicsI have most of the code working and getting the string with preg_match("/office\s*:\s*
Example.
if the divert = office:0
echo Diversion is off
else divert = office:1
echo Diverted to Office 1
else divert = office:2
echo Diverted to Office 2
I want to read a portion of text (office : 0 ) output from Asterisk AMI (Asterisk Manager Interface) when we issue the AMI command database showkey divert .
Sample output (from php script - code below)
Asterisk Call Manager/1.0 Response: Success Message: Authentication accepted Response: Follows Privilege: Command /divert/office : 0 --END COMMAND-- Response: Goodbye Message: Thanks for all the fish
Hope it make sense
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Your regex has me a little confused...
/office\s*:\s*1/ - Why the \s*?
If you are searching the string for 'office:' and that is likely to always be a fixed value, and the number after it will only be a 0 or a 1, then why not have your regex be more like this?
/office:[0|1]/
This will ONLY match when the word office, a semi-colon and a 0 or 1 is detected.
Also, in your preg_match, you need only to have $matches and not the [0]. Any matches that it does find will auto populate the $matches array, from which you can then test against the array values.
Additionally, once you have a match, you should extract just the last character from the match and use it in an immediate if to assign the 'off'.
Hope this helped. :)
~A~
Thanks for the help and information on regex I have not used regex much and learning php. I will try out what you have suggested.
The goal of the project is to see if office phones are diverted, where to and the ability to divert them remotely all from a webrowser. All systems are Asterisk running on Linux www.asterisk.org. Asterisk has an inbuilt database that can be accessed from the dial plan so it is easy to control what should happen to calls.
There are many offices and originally I was setting the value in the Asterisk database by the first three letters of the office location and matching bri, mar, gol etc. I though it would make it easer to read in the asterisk dial plan and php instead of looking at a numeric value, thats why I was using it that way but the value can be numeric.
Before I read your post I had managed to get it working (see attached code) with a lot of if statements (and will need to add more for the others offices). I am sure there is a more efficient way to do. I tried PHP Switch Statement but due to my inexperience I was unable to get it working.
I would be interested it you thoughts.
Thanks
I urge you to examine the code I sent you.
It is performing exactly as desired, then extracts the office number.
It also will create the text, 'Diversion is off" if the number equals zero and if greater than zero, will display "Dieverted to office n", where 'n' is the office number pulled out of the regex match.
No need for a switch or endless list of ifs. If you use the code I provided, it will work for any number of offices.
~A~
Ahhh...very well then. That would explain your regex's use of the \s then.
Anyway, I do hope the remaining logic suits your desired results. If a database derived name is what you wish to have, then I hope that the numbers stripped from the diversions refer to a primary key of a locations table or something to that effect.
~A~
Business Accounts
Answer for Membership
by: bwilks99Posted on 2009-10-17 at 01:08:49ID: 25595205
Increased points hope this helps.