broshman
03-23-2004, 09:14 PM
Hi,
I am currently reading in proxies from a file, and some examples of proxie.txt are below:
200.241.56.130:80
200.115.207.125:6588
200.180.225.234:80
200.217.102.142:3128
200.170.1.230:8080
Now, what I am trying to do is seperate everything before the : to $host and everything after the : to $port
My code is below
$fp=fopen("proxies.txt", 'r') or die("Could not open proxies.txt!");
while(!feof($fp)){
$line=fgets($fp, 1024);
$pos=strpos($line, ':');
$host=substr($line, 0, $pos);
$port=substr($line, ($pos+1), (strlen($line)-1));
print "Port length: ".strlen($port)."<br>";
print "Host=$host<br> Port=$port<br>";
}
Now, the problem is, is that there is a space " " at the end of $host, which I have no idea where it is coming from. When I do Port length on the first proxy, 200.241.56.130:80, it says the length is 3 when really it is 2, because 80 is 2 digits.
I have tried millions of ways of getting rid of the space or putting everything except the space in a string, but no success.
If anyone has an idea why, please let me know!
I am currently reading in proxies from a file, and some examples of proxie.txt are below:
200.241.56.130:80
200.115.207.125:6588
200.180.225.234:80
200.217.102.142:3128
200.170.1.230:8080
Now, what I am trying to do is seperate everything before the : to $host and everything after the : to $port
My code is below
$fp=fopen("proxies.txt", 'r') or die("Could not open proxies.txt!");
while(!feof($fp)){
$line=fgets($fp, 1024);
$pos=strpos($line, ':');
$host=substr($line, 0, $pos);
$port=substr($line, ($pos+1), (strlen($line)-1));
print "Port length: ".strlen($port)."<br>";
print "Host=$host<br> Port=$port<br>";
}
Now, the problem is, is that there is a space " " at the end of $host, which I have no idea where it is coming from. When I do Port length on the first proxy, 200.241.56.130:80, it says the length is 3 when really it is 2, because 80 is 2 digits.
I have tried millions of ways of getting rid of the space or putting everything except the space in a string, but no success.
If anyone has an idea why, please let me know!
