View Full Version : can someone help me with this trim and conditional statement

11-28-2006, 04:15 PM
$_REQUEST['statement'] = (trim($_REQUEST['statement']) != "" ? $_REQUEST['statement'] : $_LANG['Nostatement']);

Hi all,

Can someone tell me what the above is doing? Statement is always truncated in output, obviously because of trim, but what does the whole statement do?

Can i just take out trim?
Is the trim the problem, i thought it only takes out whitespaces.

11-28-2006, 04:25 PM
It is the equivalent of:

if((trim($_REQUEST['statement']) != "")
$_REQUEST['statement'] = $_REQUEST['statement'];
$_REQUEST['statement'] = $_LANG['Nostatement'];

The ?: is called a ternary operator.
BTW The code should check if $_REQUEST['statement'] is actaully set before doing things with it.

11-28-2006, 04:55 PM
yes ur right

so this isn't the line of code truncating output?

11-28-2006, 06:08 PM
No, the value is trimmed for comparison. But it's not changed if the trimmed value is not an empty string.