} else {
        // not a header, but message
        if (preg_match("/http:\\/\\/www.vtc.com\\/products\\/[\\w\\s\\-\\!]+\\.(htm)/", $lines[$i], $matches)) {
            $link = $matches[0];
        }
        $message .= $lines[$i] . "\n";
    }
    if (trim($lines[$i]) == "") {
        // empty line, header section has ended
        $splittingheaders = false;
    }
}
$post = $subject . "\n" . $link;
// shorten the url and twitter
$link = urlencode($link);
$productUrl = "http://api.bit.ly/v3/shorten?login="******"&apiKey=" . $apikey . "&longUrl=" . $link . "&format=json";
$short = file_get_contents($productUrl);
$s = json_decode($short);
// Send to twitter
include_once 'twitter/twitter.php';
$curTwitter = new twitter("vtc", $vtcpass);
if ($s->status_txt == 'OK') {
    $shorturl = $s->data->url;
    $twitter_status = $subject . " - " . $shorturl . " #tutorials #vtc";
    $curTwitter->setStatus($twitter_status);
    mail($to, $subject, $shorturl, 'From:release@example.com');
} else {
    $er = $s->status_txt;
    $x = $er . " : " . $link;
    mail($to, $subject, $x, 'From:release@example.com');
}
Пример #2
0
<?php

include_once 'twitter.php';
$curTwitter = new twitter("Stockchase", "7467632acton");
if (isset($_POST['submit'])) {
    $twitter_status = $_POST['twitter_stat'];
    if (strlen($twitter_status) > 0) {
        if ($curTwitter->setStatus($twitter_status) == true) {
            echo "<p>Updated Succesfully</p>";
        } else {
            echo "<p>Twitter is unavailable at this time</p>";
        }
    } else {
        echo "<p>Error: I won't send blank messages!</p>";
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>Set your status on Twitter</title>
</head>
<body>
	<h2>Set your status on Twitter</h2>

<p><strong>What are you doing?</strong></p>
	<form action="<?php 
echo $_SERVER['PHP_SELF'];
?>