|
-
October 16th, 2008, 01:06 AM
#1
Re: Unicode in php
One more question i need to make an array of items i type in a form so i used $_POST
but it works strangely it puts the entire array in pos 0
so arr has the entire "4","6","aga","aza","goo","1" in arr[0] but arr2 which is hard coded works fine why is that?
$arr = array($_POST['pname']);
$arr2 = array("4","6","aga","aza","goo","1");
-
October 16th, 2008, 06:36 AM
#2
Re: Unicode in php
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 16th, 2008, 06:41 AM
#3
Re: Unicode in php
$_POST always returns an associative array based on the names of the HTML elements passed in the form. You don't need to put it into one.
If you put and array as a value of an array (your first example of code) it will make it a two-dimensional array. That is how it is supposed to work.
PHP Code:
$pname = $_POST['pname'];
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 16th, 2008, 09:36 AM
#4
Re: Unicode in php
Sorry for the split thread thing and thanks for your answer i understand now how it works but it doesn't solve my problem.
i want to receive things from the form to an array so that if i wrote a list say 1,2,3,4,5 i will get an array of 12345 one in each cell but $_POST seems to put each character to each cell so instead i get 1,2,3 as my array
-
October 16th, 2008, 12:28 PM
#5
Re: Unicode in php
You're not making sense. Perhaps you can post more of your code to the form you are submitting.
Let me see if I can clear this up, and then you can explain in more detail what you are attempting.
$_POST is an associative array. Its members come from all <input> and <select> HTML tags of a given form. The keys correspond the the tags name attribute.
For example...
Code:
<form ...>
<input type="hidden" name="id" value="42" />
<input type="text" name="firstname" value="Jose" />
<input type="text" name="lastname" value="Fulano" />
</form>
Will produce the following server-side...
Code:
array (
"id" => 42,
"firstname" => Jose,
"lastname" => Fulano
)
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 16th, 2008, 02:39 PM
#6
Re: Unicode in php
Yeah i got that from your previous post but in my case instead of having just one input in the form like jose i have a list like this
red,black,blue,green
and i want to be able to have that list in an array so i can get the items one by one but it seems that $_post takes that list as one item
now for what i'm trying to do
i'm using a loop to write
<li><a href="1.php">Main</a>
severl times it's a menu so i need all the pages so i'm using the counter from the loop to fill the page name like so
<li><a href="$count.php>Main</a>
this is done in separate parts of course and then connected together but instead of main i need the names for the pages so i want to be able to put a list in a form and then an array and just access the list items from the array using the loop like so
$arr[$count];
i hope i explained well (i'm pretty bad at explanations..)
-
October 16th, 2008, 03:01 PM
#7
Re: $_POST returns array
If I understand you correctly, you're passing a comma separated list of values as an entry for a given key. When accessing it via $_POST, you get that list back, but you want an array.
If that's the case, access the value via $_POST and pass it through split. This will give you a further array that you can access by element number.
http://www.php.net/split
If you want something different, you may need to change how you're POSTing the data, or will need to process it afterwards.
-
October 16th, 2008, 03:55 PM
#8
Re: $_POST returns array
I wouldn't use split() unless you want to use regular expressions. In this case, I would use explode().
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 16th, 2008, 10:18 PM
#9
Re: $_POST returns array
Thanks a lot both of you now it works as it should
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|