Re: Syntax
| From: | Karl DeSaulniers | Date: | Wed, 23 Sep 2015 07:33:45 +0000 |
| Subject: | Re: Syntax | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325133@lists.php.net to get a copy of this message | ||
On Sep 23, 2015, at 12:11 AM, Jim Lucas <lists@cmsws.com> wrote:
>
> You should use something like this.
>
>
> $str = "-1 save";
>
> if ( preg_match("/^-1 (delete|hide|save)$/", $str ) === 1 ) {
> echo "does match";
> } else {
> echo "does not match";
> }
>
Before I go any further, here is a code example so I can make helping me a little easier. Thank you
for your attempt
function Mass_Action() {
$MassOption = isset($_POST['action_h']) && !empty($_POST['action_h']) ?
$_POST['action_h'] : isset($_POST['action_f']) &&
!empty($_POST['action_f']) ? $_POST['action_f'] : '-1';
switch($MassOption) {
case preg_match("/(-1|delete|hide|save)/i", $MassOption) !== 1 :
$message = Status_Update();
break;
case "-1": break;
case "delete all":
$message = Delete_All_Orders();
break;
case "delete":
$message = Delete_Orders();
break;
case "hide":
$message = Hide_Orders();
break;
}
return $message;
}
With this function I check to see if $MassOption equals any of the following, -1 (negative 1),
delete all, delete, hide and save is in there for future purpose.
The string can also be empty or a value other than these, like a status shipping, completed, new,
etc.
So on the first one, it checks that none of the hardcoded values are present (this is what I am
trying to get working)
The second fails the function silently in essence not doing anything.
The rest are self explanatory.
Currently, the $MassOption is coming out -1 but still firing the preg_match statement.
And on a side note, what is up with the default on a switch statement?
That thing always fires no matter what, I essentially never use it because of this.
Best,
Karl DeSaulniers
Design Drumm
http://designdrumm.com