Re: Syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sep 23, 2015, at 12:11 AM, Jim Lucas <lists@xxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux