php - file_get_contents - Special characters in URL - Special case -


i'm not getting file_get_contents() return page in particular case url contains 'Ö' character.

$url = "https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=cm_949a11_1534_1603_dag_dst_50_Övrigt_1_1&type=subgroup&startdate=20150101&enddate=20300501" print file_get_contents($url); 

how make file_get_contents() work expected on url?

i have tried following solutions whithout working result:

1.

print rawurlencode(utf8_encode($url)); 

2.

print mb_convert_encoding($url, 'html-entities', "utf-8"); 

3.

$url = urlencode($url); print file_get_contents($url); 

4.

$content = file_get_contents($url); print mb_convert_encoding($content, 'utf-8', mb_detect_encoding($content, 'utf-8, iso-8859-1', true)); 

found in these questions:

file_get_contents - special characters in url

php url special characters without urlencode:ing them!

file_get_contents() breaks utf-8 characters

update: can see page returned in example not expected page, 1 when type url in browser.

urls cannot contain "Ö"! start basic premise. characters not within narrowly defined subset of ascii must url-encoded represented within url. right way urlencode or rawurlencode (depending on format server expects) individual segment of url, not url whole.

e.g.:

$url = sprintf('https://se.timeedit.net/web/liu/db1/schema/s/s.html?tab=3&object=%s&type=subgroup&startdate=20150101&enddate=20300501',                rawurlencode('cm_949a11_1534_1603_dag_dst_50_Övrigt_1_1')); 

you still need use correct encoding string! Ö in iso-8859-1 url encoded %d6, while in utf-8 encoded %c3%96. 1 correct 1 depends on server expects.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -