PHP页面在objective-C中返回垃圾而不是返回字符串

I'm building an iOS app using Xcode. In that, I need to get a value from an online php page: index.php.

I don't know how to do that. I've tried the following:

    NSString *urlstr = [[NSString alloc] 
          initWithFormat:@"http://www.mediafire.com/edit/l8lba665t24h3dg/index.php"];
    NSURL *url = [[NSURL alloc] initWithString:urlstr];
    NSString *ans = [NSString stringWithContentsOfURL:url 
                                             encoding:NSASCIIStringEncoding 
                                                error:nil];
    NSLog(@"ans--------->%@",ans); // This returns the whole page :(
    [urlstr release];
    [url release];

Is it is the right way to do this? Then how to get the return string? I need the return string only as: "Hello, PHP!" (ie., the php output). Please, please help me...

yes it's the right way, you have the same result on your NSLog as rigth click on your page and show source code. Your url index.php is in plain text and not interpreted by the server, is why you haven't "Hello, PHP!" as a result.

see php hello world tutorial : http://www.utexas.edu/learn/php/example1.shtml

the result: http://www.utexas.edu/learn/php/ex1.php

change your code :

NSString *urlstr = [[NSString alloc] 
      initWithFormat:@"http://www.utexas.edu/learn/php/ex1.php"];
NSURL *url = [[NSURL alloc] initWithString:urlstr];

That isn't a PHP page; it's an online editor containing a snippet of PHP code. You need to actually save it to a file that's served from a PHP-savvy webserver (e.g. Apache) in order to get the result of executing the script.