Perl to Php翻译

时间:2010-08-15 17:37:48

标签: php perl translation

您可以将此Perl代码转换为PHP代码吗?

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
$ua -> timeout(0.5);
my $req = POST 'http://forums.shooshtime.com/',
[ vb_login_username => 'mehdi' , vb_login_password => '***' , go => 'submit'];
my $content = $ua->request($req);

先谢谢。

1 个答案:

答案 0 :(得分:2)

你走了。完整代码转换为PHP:

<?php
//set URL
$url = 'http://forums.shooshtime.com/';

//set POST variables
$fields = array(
    'vb_login_username' => 'mehdi',
    'vb_login_password' => '***' ,
    'go' => 'submit'
                );

// set user agent
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5';

//open connection
$ch = curl_init();

//set the url, POST data, UserAgent, Timeout, etc.
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 500); //time out of 0.5 seconds.

//execute post
$content = curl_exec($ch);

//close connection
curl_close($ch);
?>