Re: [PHP] Array to String

2006-06-28 Thread Jochem Maas
Richard Lynch wrote:
> On Mon, June 26, 2006 2:06 am, Jochem Maas wrote:
>>>   if (!get_magic_quotes_gpc()) {
>>> if (isset($_POST)) {
>>> foreach ($_POST as $key => $value) {
>>> $_POST[$key] = trim(addslashes($value));
>>> }
>>> }
>>>
>>> if (isset($_GET)) {
>>> foreach ($_GET as $key => $value) {
>>> $_GET[$key] = trim(addslashes($value));
>>> }
>>> }
>>> }
> 
> If this is all your code is trying to do, then you might as well turn
> on Magic Quotes GPC in the first place, which means you've got bigger
> problems than this already...

seems that when I answered the OP I totally misread the code and assumed
we wanted to stripslashes when magic quotes wedre on (as opposed to
the other way around) - I guess my brain refused to accept someone would want
to do it the other way around and 'fixed' the code into something else.

oh well. the recursive function idea is still worthwhile even though the
actual example I gave is borked.

and for the rest: "what Richard said"

> 
> If it's just some legacy code you need to get running, fine and dandy.
> 
> If this is a new project you are starting on, find a more recent
> tutorial about Magic Quotes and SQL Injection attacks before you go
> any further.
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array to String

2006-06-27 Thread Richard Lynch
On Mon, June 26, 2006 2:06 am, Jochem Maas wrote:
>>   if (!get_magic_quotes_gpc()) {
>> if (isset($_POST)) {
>> foreach ($_POST as $key => $value) {
>> $_POST[$key] = trim(addslashes($value));
>> }
>> }
>>
>> if (isset($_GET)) {
>> foreach ($_GET as $key => $value) {
>> $_GET[$key] = trim(addslashes($value));
>> }
>> }
>> }

If this is all your code is trying to do, then you might as well turn
on Magic Quotes GPC in the first place, which means you've got bigger
problems than this already...

If it's just some legacy code you need to get running, fine and dandy.

If this is a new project you are starting on, find a more recent
tutorial about Magic Quotes and SQL Injection attacks before you go
any further.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array to String

2006-06-26 Thread Jochem Maas
weetat wrote:
> Hi all,
> 
> I have the error below in my PHP version 4.3.2:
> 
> PHP Notice:  Array to string conversion in /data/html/library/config.php
> on line 45
> 
> If i have turned "on" the magic_quotes in php.ini, it is ok .
> Any ideas?
> 
> It cause by the code below:
> 
>   if (!get_magic_quotes_gpc()) {
> if (isset($_POST)) {
> foreach ($_POST as $key => $value) {
> $_POST[$key] = trim(addslashes($value));
> }
> }
> 
> if (isset($_GET)) {
> foreach ($_GET as $key => $value) {
> $_GET[$key] = trim(addslashes($value));
> }
> }
> }

// you might find something *like* this to be more flexible:

function arrayStripSlashes($v)
{
if (is_array($v)) {
foreach ($v as $key => $value) {
$v[$key] = arrayStripSlashes($value);
}
} else if (is_scalar($v)) {
$v = trim(addslashes($v));
} else {
$v = null;
}

return $v;
}

if (!get_magic_quotes_gpc()) {
$_POST = arrayStripSlashes($_POST);
$_GET  = arrayStripSlashes($_GET);
}


> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array to String

2006-06-25 Thread Chris
You are probably passing some variables into POST or GET using the array 
notation:


/mypage.php?var[]=fred&var[]=wilma

$_GET['var'] will be an array inside mypage.php, You should probably 
check to see if it's an array then, if it is, loop through each element 
of the var array


Chris

weetat wrote:

Hi all,

I have the error below in my PHP version 4.3.2:

PHP Notice:  Array to string conversion in 
/data/html/library/config.php on line 45


If i have turned "on" the magic_quotes in php.ini, it is ok .
Any ideas?

It cause by the code below:

  if (!get_magic_quotes_gpc()) {
if (isset($_POST)) {
foreach ($_POST as $key => $value) {
$_POST[$key] = trim(addslashes($value));
}
}

if (isset($_GET)) {
foreach ($_GET as $key => $value) {
$_GET[$key] = trim(addslashes($value));
}
}
}



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array to String conversion error

2004-03-16 Thread Alex Hogan
> $row is an entire array. you don't explode an entire array, you only
> explode the contents of an element of an array.
> 
> print_r($row) will give you some clues.
> 
> you'll need to access a specific element within the array. like:
> 
> $thearray = explode('__', $row[0][0]);

That was it... Thanks Chris.


alex


** 
The contents of this e-mail and any files transmitted with it are 
confidential and intended solely for the use of the individual or 
entity to whom it is addressed.  The views stated herein do not 
necessarily represent the view of the company.  If you are not the 
intended recipient of this e-mail you may not copy, forward, 
disclose, or otherwise use it or any part of it in any form 
whatsoever.  If you have received this e-mail in error please 
e-mail the sender. 
** 




RE: [PHP] Array to String conversion error

2004-03-16 Thread Chris W. Parker
Alex Hogan 
on Tuesday, March 16, 2004 9:48 AM said:

> $row = mssql_fetch_array($result);
> 
> $thearray = explode('__', $row); - This is line 40

$row is an entire array. you don't explode an entire array, you only
explode the contents of an element of an array.

print_r($row) will give you some clues.

you'll need to access a specific element within the array. like:

$thearray = explode('__', $row[0][0]);

> What am I missing?

unless i'm wrong, the above.



chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array to string?

2003-10-14 Thread Douglas Douglas
I just found it: implode. Sorry to bother you.

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array to string

2001-10-19 Thread R'twick Niceorgaw

try this
$fupdatecontents='';
while ( list($key,$value) = each($fcontents) ) {
$fupdatecontents .=$value;
}
$fcontents = $fupdatecontents;

or just write $fupdatecontents into the file.
You may need to add a \n after each line ( which I'm not sure);. If you need
you can change the

$fupdatecontents .=$value;

line to

$fupdatecontents .=$value."\n";

HTH
R'twick
- Original Message -
From: "René Fournier" <[EMAIL PROTECTED]>
To: "Php-General" <[EMAIL PROTECTED]>
Sent: Friday, October 19, 2001 12:05 PM
Subject: [PHP] array to string


> Just trying to convert an array to string before writing the whole thing
> back out to a file.  (Trying to do a simple database-less database, using
> text files).
>
> $fcontents = file($name.".db");  // THE ENTIRE TABLE
> $fcontents[$update] = $updatedstring;  // THE ROW TO BE UPDATED
> $fp = fopen($name.".db", "w+");
>
> But before the next line, I need to convert $fcontents to a string, else
> just "Array" gets written to the text file.  I just can't seem to find the
> sure-to-be simple command to do this on php.net or phpbuilder.com, etc.
Any
> ideas?
>
> fwrite($fp,$fcontents);
> fclose($fp);
>
> Thanks.
>
> ...Rene
>
> ---
> Rene Fournier
> [EMAIL PROTECTED]
>
>
> _
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] array to string

2001-10-19 Thread Steve Werby

"René Fournier" <[EMAIL PROTECTED]> wrote:
> Just trying to convert an array to string before writing the whole thing
> back out to a file.  (Trying to do a simple database-less database, using
> text files).
>
> $fcontents = file($name.".db");  // THE ENTIRE TABLE
> $fcontents[$update] = $updatedstring;  // THE ROW TO BE UPDATED
> $fp = fopen($name.".db", "w+");
>
> But before the next line, I need to convert $fcontents to a string, else
> just "Array" gets written to the text file.  I just can't seem to find the
> sure-to-be simple command to do this on php.net or phpbuilder.com, etc.
Any
> ideas?

See implode().

$fcontents_string = implode( '', $fcontents );

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]