Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can someone help me with this trim and conditional statement

    Code:
    $_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.
    Last edited by LondonBoy; 11-28-2006 at 03:23 PM.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    It is the equivalent of:
    PHP Code:

    if((trim($_REQUEST['statement']) != "")
    {
        
    $_REQUEST['statement'] = $_REQUEST['statement'];
    }
    else
    {
         
    $_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.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes ur right

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

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    No, the value is trimmed for comparison. But it's not changed if the trimmed value is not an empty string.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •