Dealing with space in PHP get variable

Put your problem here if it does not fit any of the other categories.

Dealing with space in PHP get variable

Postby ramgraph1 » Wed Feb 27, 2008 3:23 pm

I am using code like the following to send info to a php file:

Code: Select all
String URLaddString = ("?name=" + name + "&title=" + title);
String newURL = ("http://www.mydomain.com/newentry.php" + URLaddString);


The problem that I have is that using a "name" or "title" with a space in it causes an exception. Is there a way I can adjust the code to allow spaces?
Thanks.
ramgraph1
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Wed Jan 09, 2008 10:03 pm

Top

Postby Ishtar » Thu Feb 28, 2008 10:35 am

http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

You need url encoding! Spaces(almost everything not a-zA-Z0-9) are NOT allowed in urls. Replace space with "%20" or "+".

Use this to also encode other characters,
http://code.google.com/android/reference/java/net/URLEncoder.html

[edit]
http://www.anddev.org/doing_http_post_with_android-t492.html

Plusminus uses this function for his POST.

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Postby ramgraph1 » Fri Feb 29, 2008 7:32 am

Thanks for your reply. I'll see what I can do with these.
ramgraph1
Experienced Developer
Experienced Developer
 
Posts: 68
Joined: Wed Jan 09, 2008 10:03 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 21 guests