This is a php boolean expression verifier/parser I built for a Postgres full text index search input.
A while back I searched quite heavily, mainly on Google, to find a PHP program to validate a boolean expression, specifically for the format used in querying a Postgres database with a full text field. After trial and error, I came up with the function here, which seems to do the trick. I put it on Github in case anybody needs to validate a boolean expression in PHP.
Please let me know if this routine causes any problems.
Change Log
2015-02-26 -- Fixed an embarrassing error
2015-02-05 -- Fixed a couple of bugs dealing with error messages
- Fixed the error messages, especially beginning and ending
- Added a test for ending messages
2014-10-23 -- Fixed bug and changed away from Postgres tokens output default
- Added error for occurrence where tokens exist in output boolean operators. This error can happen when input boolean definition is different than output boolean definition.
- Code now parses on input boolean definition, not Postgres definition when input definition is defined. Will not default output Postgres boolean full text operators when input booleans are defined.
2014-10-08 -- Fixed 2 critical bugs
2014-10-05 -- Major changes -- Basically Version 2
- Project renamed to php-boolean-validator
- Turned into an object
- Support added for any boolean operator tokens scheme
- Toggle flag added for auto-populating ORs
- Redundant procedure removed
- Removed unnecessary parameter
- General housekeeping
- Test code separated into separate file
2014-09-21 -- Added support for plain english boolean commands and for boolean_tokens array
2014-01-16 -- Fully redid the function making major logical and programming changes
2013-12-22 -- Changes made to remove notices for PHP 5.4
2013-11-06 -- Initial upload and get everything going