首页 > php代码

php 在服务器上载文件

这个例子将解释您如何上传FTP服务器上的文件。 ftp_put()命令允许上传在服务器上现有的文件。对于上传到FTP服务器的文件,首先你必须先登录到FTP服务器上,搜索源文件上传。定义源文件的目标路径。

阅读全文

php 创建图片程序实例

<?php
$height = 300;
$width = 300;
 
$image = ImageCreate($width, $height);
 
$grey = ImageColorAllocate($image, 125, 125, 125);
$blue = ImageColorAllocate($image, 0, 0, 255);
$red = ImageColorAllocate($image, 255, 0, 0);
 
ImageString ($image, 4, 50, 50, "Size 4 Font", $red);
ImageString ($image, 5, 50, 100, "Size 5 Font", $blue);
 
ImageLine($image, 0, 0, 300, 300, $blue);
 
 
header ("Content-type: image/png");
ImagePng($image);
ImageDestroy($image);
?>

阅读全文

从数组中删除空白的元素(包括只有空白字符的元素)

 /**
 *
 *
 * @param array $arr
 * @param boolean $trim
 */
function delete_empty(& $arr, $trim = true)
{
    foreach ($arr as $key => $value) {
        if (is_array($value)) {
            delete_empty($arr[$key]);
        } else {
            $value = trim($value);
            if ($value == '') {
                unset($arr[$key]);
            } elseif ($trim) {
                $arr[$key] = $value;
            }
        }
    }
}

阅读全文

将一个二维数组转换为 hashmap 哈希表

/**
 * 将一个二维数组转换为 hashmap
 *
 * 如果省略 $val 参数,则转换结果每一项为包含该项所有数据的数组。
 *
 * @param array $arr
 * @param string $keyField
 * @param string $val
 *
 * @return array
 */
function arrHash(& $arr, $keyField, $val = null)
{
    $ret = array();
    if ($val) {
        foreach ($arr as $row) {
            $ret[$row[$keyField]] = $row[$val];
        }
    } else {
        foreach ($arr as $row) {
            $ret[$row[$keyField]] = $row;
        }
    }
    return $ret;
}

阅读全文