-5

How can I use PHP's $_GET in Objective-C? I would like to use it on an NSString:

http://baileyseymour.com/QR/data-processor.php?name=John%20Smith&email=example@icloud.com

I want to get the value of name and/or email in the uri.

I want to split the NSString of the URL into 2 parts. name=John%20Smith and email=example@icloud.com

How can I accomplish this?

atomikpanda
  • 1,845
  • 5
  • 33
  • 47
  • Perhaps you could describe your desired result? – jscs Jul 13 '13 at 18:53
  • @JoshCaswell I believe he wants a dictionary of the GET parameters, i.e. `@{@"name": "John Smith", @"email: ...}` – cobbal Jul 13 '13 at 18:57
  • 1
    possible duplicate of [Best way to parse URL string to get values for keys?](http://stackoverflow.com/questions/8756683/best-way-to-parse-url-string-to-get-values-for-keys) – Kevin Jul 13 '13 at 19:09

2 Answers2

1

How can I use PHP's $_GET in Objective-C? I would like to use it on an NSString:

You cannot. Objective-C is not PHP, so there's nothing to evaluate a PHP symbol in an Obj-C context. If you want to do something similar, that's certainly possible but you'll need to describe your situation in a little more detail.

Caleb
  • 124,013
  • 19
  • 183
  • 272
1

I'm not sure what your goal is, but here is a short example of how to use UIWebView to interact with a PHP document via URL variables.

// Objective-C
UIWebView *scoreContent;
scoreContent = [[UIWebView alloc] init];
NSString *email = @"you@domain.com";
NSString *webURL = [NSString stringWithFormat:
                    @"http://yourdomain.com/objc.php?email=%@",
                    email];

[scoreContent loadRequest:
 [NSURLRequest requestWithURL:[NSURL URLWithString:webURL]]
];

Then in the PHP file you could just do something like this:

<?php
//objc.php
echo 'Your email is: ' . $_GET['email'] . '.';
?>

I would have compiled the Objective-C to make sure it works because I just copied it from a game I made, but if it doesn't work let me know and I'll fix it if you can't.

SISYN
  • 2,209
  • 5
  • 24
  • 45