473,372 Members | 1,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Array to string conversion error - why?

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
4 66855
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

"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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: John van Terheijden | last post by:
Hi. I'm trying to make a conversion algorithm that colors even and odd words in a HTML string with <div> tags. // input text with all sorts of HTML tags and whitespace $str = "<h1>Title...
3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
9
by: Ronald Fischer | last post by:
Assume the following JavaScript function: function bracketize(s) { return ''; } This function which doesn't assume anything about its argument except that it must be convertible to a string.
12
by: Alexander Stippler | last post by:
Hello, I've got a quite simple question. I want to have something like int main() { double array = {{1,2,3}, {4,5,6}, {7,8,9}}; double **field; field = array;
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
6
by: Ecohouse | last post by:
I have a field in a recordset which is a string. It can look like this: 13-15-67-56 I need to break out this string into numbers to run in queries to open recordsets. But when I try to open...
2
by: Dabbler | last post by:
I'm getting the following error when I try and insert a row using FormView, ObjectDataSource and stored procedure. The form has 40+ columns on it and I'm not sure how to diagnose where the problem...
26
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
2
by: Chris H | last post by:
Hi, I'm trying to concatenate a Description (nchar(100)) and Date (datetime) as Description and my initial effort was just "...description+' '+open_date as description..." which throws a date/...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.