Welcome to WebmasterWorld Guest from 54.198.93.179

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Parse error - trim function

     
9:33 pm on Jun 1, 2007 (gmt 0)

10+ Year Member



Hi guys,

I cant work out what I have done wrong?

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$'

PHP Code:
// Check for a database name
if(empty(trim($db)){
$errors = 'Please enter the name of your database.';
}

Can anyone help?

10:06 pm on Jun 1, 2007 (gmt 0)

5+ Year Member



Hi,

The empty function is special because it can only accept a variable as an argument, you need to do:


$temp = trim($db);
if(empty($temp)){

or

if(strlen(trim($db)) == 0){

Andrew

[edited by: Little_G at 10:25 pm (utc) on June 1, 2007]

10:09 pm on Jun 1, 2007 (gmt 0)

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If $db is empty why would you trim it?
10:10 pm on Jun 1, 2007 (gmt 0)

5+ Year Member



if(empty(trim($db)){
$errors = 'Please enter the name of your database.';
}

you left one of the closing brackets.

if(empty(trim($db))[b])[/b]{
$errors = 'Please enter the name of your database.';
}

[edited by: Mohamed at 10:11 pm (utc) on June 1, 2007]

10:23 pm on Jun 1, 2007 (gmt 0)

10+ Year Member



thanks for the reply guys :)

I did miss a bracket, yes...
However this is still giving same error?

[PHP]
if(empty(trim($db))){
$errors = 'Please enter the name of your database.';
} [/PHP]

5:15 am on Jun 2, 2007 (gmt 0)

5+ Year Member



Hi,

This may not look good as the earliers. But I hope it will do the trick.
<?php
$test=trim($db);
if($test=="")
{
echo("Please enter the name of the Database.");
}
?>

10:44 am on Jun 2, 2007 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



adammc,

As previously mentioned, empty only checks vars. From the PHP website:


Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

Why not use:

if (trim($db)=='')
{
echo("Please enter the name of the Database.");
}

dc

 

Featured Threads

Hot Threads This Week

Hot Threads This Month