Page 1 of 1

Message: trim() expects parameter 1 to be string, array give

PostPosted: 06. December 2010 22:12
by mikealex2k12
I installed a site engine and I get this error...

A PHP Error was encountered
Severity: Warning

Message: trim() expects parameter 1 to be string, array given

Filename: libraries/SmartyExtended.php

Line Number: 41

.....

Is there any way to make this message to away?

Re: Message: trim() expects parameter 1 to be string, array

PostPosted: 06. December 2010 22:43
by WilliL
mikealex2k12 wrote:Message: trim() expects parameter 1 to be string, array given
Filename: libraries/SmartyExtended.php
Line Number: 41
Is there any way to make this message to away?

Yes, I think you have to debug your code and find the wrong code.
trim() is used for stings not for arrays.
If you are using a code like this "$_POST = array_map( 'trim', $_POST );" be sure that there is no array in $_POST
analyse $_POST['test'][0] and unset this variable before using trim().

Re: Message: trim() expects parameter 1 to be string, array

PostPosted: 06. December 2010 22:46
by Altrea
sure. Use the trim function in the right way.

wrong way
Code: Select all
<?php
$output = array( ' foo', ' bar ', 'baz ' );
$cleanoutput = trim( $output );


right way (single vars)
Code: Select all
<?php
$output = ' foo';
$cleanoutput = trim( $output );


right way (arrays)
Code: Select all
<?php
$output = array( ' foo', ' bar ', 'baz ' );
$cleanoutput = array();
foreach( $output as $value ) {
    $cleanoutput[] = trim( $value );
}