...

View Full Version : Can't use function return value in write context



captain
11-13-2007, 03:50 AM
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.

vtjustinb
11-13-2007, 03:57 AM
Empty() only works on variables, and trim returns a string--which is causing the error. I would use strlen() instead.

captain
11-13-2007, 04:37 AM
thanks,it works!

ps:what's the meaning of ${}?

vtjustinb
11-13-2007, 04:40 AM
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:


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

captain
11-13-2007, 05:00 AM
yeah,it works well

thanks for the article you recommend!

it is really a little specail usage.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum