Reputation: 17
I have a simple PHP script that just returns the string "hi" Here's the code:
<?php include "base.php"?>
<?php
echo "hi";
?>
In xCode I get the following:
2014-12-15 10:56:24.048 MyApp[12515:1603] resultString =
hi
For some reason it adds a new line before the string. How can I prevent this new line from being generated? Is it the way I'm encoding the string? Here's my string
NSString *resultsString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
THIS WAY IT WORKS!!
<?php
include "base.php"
echo "hi";
?>
Upvotes: 0
Views: 76
Reputation: 15015
You can try like this:-
//Assuming below string after reading from PHP
NSString *resultsString = @"\nhi";
//So try below api to replace new line
NSString *modifiedString = [resultsString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSLog(@"%@",modifiedString);
Upvotes: 0
Reputation: 1748
Can't offer much help with the Objective C side of things, but does there happen to be a stray newline in your php file? Remember, anything outside of the <?php ?>
tags is interpreted literally in PHP. Try removing the closing ?>
- this is actually preferred for pure-code PHP files, since the end of the code implies closing the code block and it prevents trailing newlines from affecting anything.
Upvotes: 1