473,800 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array to string conversion error - why?

I get the following error:

Notice: Array to string conversion in C:\Documents and
Settings\ShepMo de\Desktop\Webs ites\ShareMonke y.net\Web\join. php on line 11
in this code:

$input = array(array("Fi rst
Name",$_POST['firstname']),array("Surnam e"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POS T['email']),array("Userna me"=>$_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($v alue,"@") 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 66913
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\ShepM ode\Desktop\Web sites\ShareMonk ey.net\Web\join .php on line 11
in this code:

$input = array(array("Fi rst
Name",$_POST['firstname']),array("Surnam e"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_PO ST['email']),array("Userna me"=>$_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($v alue,"@") 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.c om...
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\ShepM ode\Desktop\Web sites\ShareMonk ey.net\Web\join .php on line 11

in this code:

$input = array(array("Fi rst
Name",$_POST['firstname']),array("Surnam e"=>$_POST['surname']),array("Compa

n
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_PO ST['email']),array("Userna me"=>$_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($v alue,"@") 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("Fi rst
Name",$_POST['firstname']),array("Surnam e"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_POS T['email']),array("Userna me"=>$_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("Fi rst
Name",$_POST['firstname']),array("Surnam e"=>$_POST['surname']),array("Compan
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_PO ST['email']),array("Userna me"=>$_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.c om...
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("Fi rst


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

n
y Name"=>$_POST['company_name']),
array("Website / Application
URL"=>$_POST['url']),array("Email
Address"=>$_PO ST['email']),array("Userna me"=>$_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
2188
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 here</h1> <p>This is a <strong>nice</strong> <img src="picture.gif" /><br> and some nice text </p>";
3
3742
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 function 1) parsedate function failed if a date string like below format "16-MAY-2005 01:26" 2)parsedate_tz function also failed if a date string
9
1847
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
1578
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
34151
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 Encoding.Convert, but that needs byte arrays. Thanks, /Ger
6
2279
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 the recordset I get the data conversion error 3421. I have tried using the format function to convert the string and it
2
1872
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 is, the data object class, the business class etc? Object of type 'System.Int32' cannot be converted to type 'System.String'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
26
6303
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 of values to them based on data submitted from POST Fields. Code below: $_SESSION = array();
2
8653
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/ string conversion error; finally came up with a working string below but don't think it's the optimal way to do this - any suggestions? select (rtrim(description)+' '+rtrim(convert(char(2),datepart(mm,open_date)))...
0
9695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10514
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10287
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3770
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.