|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-10-29 21:28 UTC] invictible at live dot co dot uk
Description: ------------ I've been looking for a solution on PHP as I need some way to evaluate expressions within strings. Since with if: $str = '5>6'; if($str) Would evaluate as true regardless of the expression. A good possible solution for this may be a function for evaluating the expressions in the string, eg. evalexp($str); which would return true or false based on the expression within the string. Eval is an alternative however, it can create security issues when used with user provided content for obvious reasons. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 05:00:01 2025 UTC |
So, instead of having to run an if statement in eval, you can simply do something like compare('5>6 || 2<3'); So, you can perform comparisons and logical operations in a way that can't currently be performed without eval(). I saw php.net/version_compare although, it doesn't seem to cater for logical operations such as && and ||. If there is another alternative then, feel free to tell me it.