CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2008
    Posts
    45

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

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Unicode in php

    [ split thread ]
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    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.

  4. #4
    Join Date
    Oct 2008
    Posts
    45

    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

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    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.

  6. #6
    Join Date
    Oct 2008
    Posts
    45

    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..)

  7. #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.

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    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.

  9. #9
    Join Date
    Oct 2008
    Posts
    45

    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
  •  





Click Here to Expand Forum to Full Width

Featured