Archive for March 7th, 2007

Using PHP’s Curl functions behind a Proxy

Using PHP’s Curl functions even if the net is accessible only thru a proxy. This is the only way curl can be used if you use GoDaddy’s hosting.

<?php
$ch = curl_init("http://rss.news.yahoo.com/rss/topstories");

curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, "http://192.168.0.15:80");
curl_setopt($ch, CURLOPT_PROXYPORT, 80);
//curl_setopt ($ch, CURLOPT_PROXYUSERPWD, "username:password");

$data = curl_exec ($ch);
curl_close($ch);
print $data;
?>

Changing separator with Perl

This will join all lines of a file together. Sometimes I have a list of something in a file, one line per item and want to convert it to a comma(colon,tab)-separated line (with no trailing separator of course) that can be used as a command-line parameter to some other tool.


perl -e '@_=; chomp(@_); print join(";",@_);' < data_file