Recommendation
Short answers
How could I return the text file the was created on the server side using the PHP?
Using a foundation object that pulls the file from the URL. The heavy lifting is being done by Php to produce the file. You just need to deposit it into a web accessible location. If security is a concern you will want to take a deeper look at the various options in the Secure Transport Reference (also if needed, search stack overflow for questions on ssl).
How to receive the file on the ios app side?
Basically choose a foundation object and then use its writeToFile methods (examples shown under details). Extended use of the NSURLConnectionDelegate protocol or the NSURLSession class (see section on Adding Download Tasks to a Session - iOS7+ required).
Samples
If you want to continue using strings to move your data around you might want to take a look at the samples found on the String Programming Guide (link):
The sample includes the key task you'd want to do after creating your string:
NSURL *URL = ...;
NSString *string = ...;
NSError *error;
BOOL ok = [string writeToURL:URL atomically:YES
encoding:NSUnicodeStringEncoding error:&error];
if (!ok) {
// an error occurred
NSLog(@"Error writing file at %@\n%@",
path, [error localizedFailureReason]);
// implementation continues ...
Details
You can use the built-in capability of your web server to support file distribution. So, in this case, Php could just deposit the text file into a web accessible folder. Once your file is created in a web accessible address you could consider using one of the ...withContentsOfURL methods that can transform the file into a usable data object of some kind...
//transform file contents into array
NSArray *array = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:@"https://www.somelocation.com/temp/test.text"]];
or
//transform file contents into nsdata
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://www.somelocation.com/temp/test.text"]];
or
//transform file contents into dictionary
NSDictionary * dictionary = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"https://www.somelocation.com/temp/test.text"]]
If you'd prefer to download the file to your system (and then work on it locally) you can transform the object created using the writeToFile methods. In that case, I'd suggest that you use the NSData to retrieve the file and then you can save that file into your local directory using:
//use this instance method on the NSData object
- (BOOL)writeToFile:(NSString *)path options:(NSDataWritingOptions)mask error:(NSError **)errorPtr
Finally, you can also wrap the entire process into a NSURLSessionDataTask if you are using iOS7. This would allow you to perform the task in an asynchronous manner (see class reference for more info).
- (NSURLSessionDataTask *)dataTaskWithURL:(NSURL *)url completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler
There is even a way to turn your content into an image using this method on the CIImage Class.
+ (CIImage *)imageWithContentsOfURL:(NSURL *)url options:(NSDictionary *)d
Other factors to consider
You may also want to work with the file after you've downloaded it and I would recommend a review of the NSFileHandle Class Reference that has an interesting section on reading and writing using blocks.
Other considerations are the possible need to secure the file depending on sensitivity of data. This might affect the process you choose to implement.