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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Can't use function return value in write context

    PHP Code:
    if(empty(trim($_POST["act_title"]))){
                
    $error .= "<p>the title should not be empty!</p>";
            } 
    is there anything wrong with the Sentence?

    if I remove the trim,it works ok.
    is life always so hard or when you are a child
    sorry for my poor English!

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    Raleigh, NC
    Posts
    273
    Thanks
    7
    Thanked 59 Times in 52 Posts
    Empty() only works on variables, and trim returns a string--which is causing the error. I would use strlen() instead.
    Last edited by vtjustinb; 11-13-2007 at 03:52 AM.

  • Users who have thanked vtjustinb for this post:

    captain (11-13-2007)

  • #3
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks,it works!

    ps:what's the meaning of ${}?
    is life always so hard or when you are a child
    sorry for my poor English!

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Location
    Raleigh, NC
    Posts
    273
    Thanks
    7
    Thanked 59 Times in 52 Posts
    Yeah I'm actually going to say not to use that ${} syntax. I've used it before and it seemed familiar, but it's actually complex (curly) syntax used for evaluating variable contents within the context of php strings--so you won't get the error but it won't do anything easier.

    What I would do is use strlen instead:

    PHP Code:
    if (!strlen(trim($_POST["act_title"]))){ 
      
    $error .= "<p>the title should not be empty!</p>"

    Last edited by vtjustinb; 11-13-2007 at 03:57 AM.

  • #5
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yeah,it works well

    thanks for the article you recommend!

    it is really a little specail usage.
    is life always so hard or when you are a child
    sorry for my poor English!


  •  

    Posting Permissions

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