views:

45

answers:

2

I am trying to split a text into an array using explode, but for some reason that does not work when the text is coming from a posted form.

If I run explode('|§|', 'qwe|§|asd|§|zxc'); I will get an array like:

Array  
(  
    [0] => qwe  
    [1] => asd  
    [2] => zxc  
)  

BUT

If this input text comes from a form define like:

<form method="post">
Input: <input type="text" name="query" size="50" value="qwe|§|asd|§|zxc"><input type="submit" value="Parse">
</form>

I am getting the following array:

Array  
(  
    [0] => qwe|§|asd|§|zxc  
)  

Im guessing this has to do with iso settings and that the text in the 'query' field has been altered in some way, but I can't understand how to fix. I have tried setting <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> and other charsets, but to no avail.

Any ideas? Thanks in advance.

+4  A: 

Just an idea: The § sign is probably be converted to url format. Try urldecode() the string first.

elsni
A: 

I'm probably mistaken on this, but § may be a unicode character, which PHP does not yet support. Thus, there may be some issues when transferring from the form to the script.

Have you tried changing it to something more... normal? Like if you did qwe|~|asd|~|zxc instead, or maybe qwe|+~+|asd|+~+|zxc if you're concerned about what somebody would enter

Slokun
Seems you are right about the unicode thing, that character seemed to be the root of the problem. I switched it to ~ and now it seems to work fine. Thanks guys.
Thomas