SOLUTION Because objective-c doesn't encode & (because it is reserved) you should create your own method. Source: Sending an amp (&) using a post with Obj-C
For my iOS and Android app I use a php script to get some data. This script has 1 argument which is a link. Basically that script looks like this:
$link= urlVariable('link');
$source = file_get_contents($link);
$xml = new SimpleXMLElement($source);
//Do stuff with the xml
But when I send a link with the & symbol it crashes on file_get_contents
Warning: file_get_contents(https://www.example.com/xxxx/name_more_names_) [function.file-get-contents]: failed to open stream: HTTP request failed!
but the full argument is
name_more_names_&_more_names_after_the_ampersand.file
I tried encoding the link before sending it to file_get_contents with no luck.
Also tried:
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
with the same results.
Does anybody know why it breaks at &? I'm no web developer but an app developer so excuse me for the lack of knowledge on this subject.
EDIT Also tried this:
$link= urlVariable('link');
$encodedLink = urlencode($link);
$source = file_get_contents($encodedLink);
This is the result:
Warning: file_get_contents(https%3A%2F%2Fwww.example.com%2Fxxxxx%2Fname_more_names_) [function.file-get-contents]: failed to open stream: No such file or directory in
EDIT #2
I found why my url stops at the & symbol. I retrieve my argument from the url with this method:
function urlVariable($pVariableName)
{
if (isset ($_GET[$pVariableName]))
{
$lVariable = $_GET[$pVariableName];
}
else
{
$lVariable = null;
}
return $lVariable;
}
and _GET() separates arguments with the & symbol right?