homepage Welcome to WebmasterWorld Guest from 54.161.185.244
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Parse error - trim function
adammc

10+ Year Member



 
Msg#: 3356245 posted 9:33 pm on Jun 1, 2007 (gmt 0)

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?

 

Little_G

5+ Year Member



 
Msg#: 3356245 posted 10:06 pm on Jun 1, 2007 (gmt 0)

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]

henry0

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



 
Msg#: 3356245 posted 10:09 pm on Jun 1, 2007 (gmt 0)

If $db is empty why would you trim it?

Mohamed

5+ Year Member



 
Msg#: 3356245 posted 10:10 pm on Jun 1, 2007 (gmt 0)

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]

adammc

10+ Year Member



 
Msg#: 3356245 posted 10:23 pm on Jun 1, 2007 (gmt 0)

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]

IndiaMaster

5+ Year Member



 
Msg#: 3356245 posted 5:15 am on Jun 2, 2007 (gmt 0)

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.");
}
?>

dreamcatcher

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



 
Msg#: 3356245 posted 10:44 am on Jun 2, 2007 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved