Reputation: 108
I am having a few problems with this code, one is that the proxies are not being displayed on a new line for each one.
Two is that instead of the "
" being displayed these weird chinese characters are being displayed 䈼㹒
<?php
$data = file_get_contents("http://proxylists.connectionincognito.com/proxies_657.txt");
//var_dump($data);
$lines = explode("/n", $data);
foreach($lines as $line)
{
echo $line;
echo "<BR>";
}
?>
Upvotes: 1
Views: 459
Reputation: 90
Not an answer, but a suggestion. Had a similar problem where PHP wrote to a file Chinese characters instead of English. No matter what I did to change the code, those same Chinese characters kept appearing in the text file. Finally I deleted the text file and ran the PHP file again, and this time it was normal. Seems trying to overwrite the file, once it got converted, always resulted in it being converted to Chinese. Once deleted, it wrote it to the new file just fine. Weird glitch.
Upvotes: 0
Reputation: 16804
Try to explode by "\n"
instead of "/n"
.
The Chinese charakters are there because the file is encoded in UTF-16, so you need to do this:
$data = mb_convert_encoding($data,'UTF-8','UTF-16');
before you start to work with the data. I made a working example here:
http://www.servisio.com/test.html
It contains these four lines:
$data = file_get_contents("http://proxylists.connectionincognito.com/proxies_657.txt");
$data = mb_convert_encoding($data,'UTF-8','UTF-16');
$lines = explode("\n", $data);
foreach($lines as $line) echo $line.'<br>';
Upvotes: 2