file get contents - PHP file_get_contents breaks up at & -
solution because objective-c doesn't encode & (because reserved) should create own method. source: sending amp (&) using post obj-c
for ios , android app use php script data. script has 1 argument link. script looks this:
$link= urlvariable('link'); $source = file_get_contents($link); $xml = new simplexmlelement($source); //do stuff xml
but when send link & symbol crashes on file_get_contents
warning: file_get_contents(https://www.example.com/xxxx/name_more_names_) [function.file-get-contents]: failed open stream: http request failed!
but full argument is
name_more_names_&_more_names_after_the_ampersand.file
i tried encoding link before sending file_get_contents 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 same results.
does know why breaks @ &? i'm no web developer app developer excuse me lack of knowledge on subject.
edit tried this:
$link= urlvariable('link'); $encodedlink = urlencode($link); $source = file_get_contents($encodedlink);
this result:
warning: file_get_contents(https%3a%2f%2fwww.example.com%2fxxxxx%2fname_more_names_) [function.file-get-contents]: failed open stream: no such file or directory in
edit #2
i found why url stops @ & symbol. retrieve argument url method:
function urlvariable($pvariablename) { if (isset ($_get[$pvariablename])) { $lvariable = $_get[$pvariablename]; } else { $lvariable = null; } return $lvariable; }
and _get() separates arguments & symbol right?
the url should have ampersands encoded:
https://www.example.com/xxxx/name_more_names_%26_more_names_after_the_ampersand.file
in php can encode path this:
$path = parse_url($url, php_url_path); $url = substr_replace($url, '/' . urlencode(substr($path, 1)), strpos($url, $path), strlen($path));
update
if have tree structure, need more work:
$path = parse_url($url, php_url_path); $newpath = '/' . str_replace('%2f', '/', urlencode(substr($path, 1))); $url = substr_replace($url, $newpath, strpos($url, $path), strlen($path));
update 2
if script called script?link=<some-url>
, need make sure <some-url>
encoded too:
script?link=https%3a%2f%2fwww.example.com%2fxxxxx%2fname_more_names_%26_more_names_after_the_ampersand.file
Comments
Post a Comment