By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

Array to string conversion error - why?

P: n/a
I get the following error:

Notice: Array to string conversion in C:\Documents and
Settings\ShepMode\Desktop\Websites\ShareMonkey.net \Web\join.php on line 11
in this code:

$input = array(array("First
Name",$_POST['firstname']),array("Surname"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POST['email']),array("Username"=>$_POST['username']),
array("Password"=>$_POST['password']));

(line 11) if (substr_count($value,"@") != 1) {
$error_message .= "The email address you have
entered is invalid.<br>";
}

Why does substr_count($value,"@") cause this notice? And since it is not an
error as such, how do I rectify it without modifying php.ini?

Thanks,

Keiron
Jul 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Fri, 29 Aug 2003 21:25:50 +0000 (UTC), "Keiron Waites"
<webmaster@-NOSPAM-sharemonkey.com> wrote:
I get the following error:

Notice: Array to string conversion in C:\Documents and
Settings\ShepMode\Desktop\Websites\ShareMonkey.ne t\Web\join.php on line 11
in this code:

$input = array(array("First
Name",$_POST['firstname']),array("Surname"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POST['email']),array("Username"=>$_POST['username']),
array("Password"=>$_POST['password']));

(line 11) if (substr_count($value,"@") != 1) {
$error_message .= "The email address you have
entered is invalid.<br>";
}

Why does substr_count($value,"@") cause this notice? And since it is not an
error as such, how do I rectify it without modifying php.ini?


Because $value is an array? Hard to say without seeing where it's assigned...

Don't hide this warning, since you've probably now counting the number of @
characters in the string 'Array', which isn't what you want...

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #2

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:1g********************************@4ax.com...
On Fri, 29 Aug 2003 21:25:50 +0000 (UTC), "Keiron Waites"
<webmaster@-NOSPAM-sharemonkey.com> wrote:
I get the following error:

Notice: Array to string conversion in C:\Documents and
Settings\ShepMode\Desktop\Websites\ShareMonkey.ne t\Web\join.php on line 11

in this code:

$input = array(array("First
Name",$_POST['firstname']),array("Surname"=>$_POST['surname']),array("Compa

n
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POST['email']),array("Username"=>$_POST['username']),
array("Password"=>$_POST['password']));

(line 11) if (substr_count($value,"@") != 1) {
$error_message .= "The email address you have
entered is invalid.<br>";
}

Why does substr_count($value,"@") cause this notice? And since it is not anerror as such, how do I rectify it without modifying php.ini?


Because $value is an array? Hard to say without seeing where it's

assigned...
Don't hide this warning, since you've probably now counting the number of @ characters in the string 'Array', which isn't what you want...


[snip]

Crap sorry, this: foreach ($input as $name => $value) { assigns the
$value.

So:

$input = array(array("First
Name",$_POST['firstname']),array("Surname"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POST['email']),array("Username"=>$_POST['username']),
array("Password"=>$_POST['password']));
foreach ($input as $name => $value) {
(line 11) if (substr_count($value,"@") != 1) {
$error_message .= "The email address you have
entered is invalid.<br>";
}
}

I don't want to hide the error, I want to fix the code :) Is there something
about the foreach that I don't understand?
Jul 16 '05 #3

P: n/a
On Fri, 29 Aug 2003 21:56:50 +0000 (UTC), "Keiron Waites"
<webmaster@-NOSPAM-sharemonkey.com> wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:1g********************************@4ax.com.. .
On Fri, 29 Aug 2003 21:25:50 +0000 (UTC), "Keiron Waites"
<webmaster@-NOSPAM-sharemonkey.com> wrote:
> I get the following error:
>
> Notice: Array to string conversion in C:\Documents and

Crap sorry, this: foreach ($input as $name => $value) { assigns the
$value.

So:

$input = array(array("First
Name",$_POST['firstname']),array("Surname"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POST['email']),array("Username"=>$_POST['username']),
array("Password"=>$_POST['password']));


So $input is an array of arrays...
foreach ($input as $name => $value) {
So each $value is an array.
(line 11) if (substr_count($value,"@") != 1) {
Running substr_count on an array doesn't make sense; the array gets turned
into the string 'Array' and a warning output.
I don't want to hide the error, I want to fix the code :) Is there something
about the foreach that I don't understand?


Not sure why you've got a load of single-element arrays inside the outer
array.

Did you want something more like:

$input = array(
"First Name" => $_POST['firstname'],
"Surname" => $_POST['surname'],
"Company Name" => $_POST['company_name'],
"Website / Application URL " => $_POST['url'],
"Email Address" => $_POST['email'],
"Username" => $_POST['username'],
"Password" => $_POST['password'],
);

?

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #4

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:6j********************************@4ax.com...
On Fri, 29 Aug 2003 21:56:50 +0000 (UTC), "Keiron Waites"
<webmaster@-NOSPAM-sharemonkey.com> wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:1g********************************@4ax.com.. .
On Fri, 29 Aug 2003 21:25:50 +0000 (UTC), "Keiron Waites"
<webmaster@-NOSPAM-sharemonkey.com> wrote:

> I get the following error:
>
> Notice: Array to string conversion in C:\Documents and
Crap sorry, this: foreach ($input as $name => $value) { assigns the
$value.

So:

$input = array(array("First


Name",$_POST['firstname']),array("Surname"=>$_POST['surname']),array("Compa

n
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POST['email']),array("Username"=>$_POST['username']),
array("Password"=>$_POST['password']));


So $input is an array of arrays...
foreach ($input as $name => $value) {


So each $value is an array.
(line 11) if (substr_count($value,"@") != 1) {


Running substr_count on an array doesn't make sense; the array gets

turned into the string 'Array' and a warning output.
I don't want to hide the error, I want to fix the code :) Is there somethingabout the foreach that I don't understand?


Not sure why you've got a load of single-element arrays inside the outer
array.

Did you want something more like:

$input = array(
"First Name" => $_POST['firstname'],
"Surname" => $_POST['surname'],
"Company Name" => $_POST['company_name'],
"Website / Application URL " => $_POST['url'],
"Email Address" => $_POST['email'],
"Username" => $_POST['username'],
"Password" => $_POST['password'],
);

?

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


Aah yes I see the error now (me = retard). Thanks a lot.

Keiron
Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.