// loop thru each line and prepend line numbers
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
4.
需要判断代码运行环境是否是 HTTPS 服务器?下面的代码可以帮助你实现,非常简单!
PHP
代码
if ($_SERVER['HTTPS'] != "on") {
echo "This is not HTTPS";
}else{
echo "This is HTTPS";
}
5.
想看看你在 facebook 有多少粉丝么?下面代码可以帮助你实现。
PHP
代码
function fb_fan_count($facebook_name){
// Example: https://graph.facebook.com/digimantra
$data = json_decode(file_get_contents("https://graph.facebook.com/".$facebook_name));
echo $data->likes;
}
6.
下面这个代码非常实用,能帮助你判断一张图片中的主色调,你可以分析任何图片。
PHP
代码
$i = imagecreatefromjpeg("image.jpg");
for ($x=0;$x<imagesx($i);$x++) {
for ($y=0;$y<imagesy($i);$y++) {
$rgb = imagecolorat($i,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> & 0xFF;
$b = $rgb & 0xFF;
$rTotal += $r;
$gTotal += $g;
$bTotal += $b;
$total++;
}
}
$rAverage = round($rTotal/$total);
$gAverage = round($gTotal/$total);
$bAverage = round($bTotal/$total);
7.