So I am a totally new to PHP. In fact, I know nothing about it. I am developing an iPhone app and aiming to get a list of items from a server. My PHP script is literally just a "echo" command.
I was wondering what would be the best way to format my list on PHP so it will look as close as possible (if not identical) to an NSArray in objective C.
So for example if my list is: AAA, BBB, CCC, DDD
By running this in obj-C:
NSArray *myAwesomeArray = [[NSArray alloc] initWithObjects: @"AAA", @"BBB", @"CCC", @"DDD", nil];
I will get this, which is what I want:
myAwesomeArray IS (
AAA,
BBB,
CCC,
DDD
)
When doing this with PHP like this (again, probably the wrong formatting for that purpose):
echo "AAA, BBB, CCC, DDD"
And this on the objc side:
NSString *urlString = @"http://......";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setTimeoutInterval:60.0];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *myPHPArray = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];
NSArray *myArray = [myPHPArray componentsSeparatedByString:@","];
I am getting this in objc for myArray:
myArray is (
AAA,
" BBB",
" CCC",
" DDD "
)
which is kind of messed up...
Appreciate any help. thanks!
See Question&Answers more detail:
os