当前位置:  编程技术>php
本页文章导读:
    ▪php将颜色名称转换为16进制表示的代码      php将颜色名称转换为16进制的表示形式。 代码:   代码示例: <?php /** * 颜色值与16进制形式的转换 * edit: www. */ $trueColors = array( 'ANTIQUE WHITE' => '#FAEBD7', 'AQUA' => '#00FFFF', 'AQUAMARINE' =&.........
    ▪php颜色值转换 php实现16进制数字与颜色值的转换      本节给出的php代码,实现了二个函数,用于将颜色值转换为16进制数字,或将16进制数字转换为颜色值。 例子:   代码示例: <?php /** * 颜色值与16进制数字的转换 * edit: WWW.JBXUE.COM */ func.........
    ▪php导入csv到MySql数据库的例子      php导入csv到MySql数据库。 代码:   代码示例: <?php /** * 将csv文件导入到mysql数据库 * edit: www. */ $databasehost = "localhost"; $databasename = "test"; $databasetable = "sample"; $databaseusername ="test"; $dat.........

[1]php将颜色名称转换为16进制表示的代码
    来源: 互联网  发布时间: 2013-12-24

php将颜色名称转换为16进制的表示形式。
代码:
 

代码示例:
<?php
/**
* 颜色值与16进制形式的转换
* edit: www.
*/
$trueColors = array(
'ANTIQUE WHITE' => '#FAEBD7',
'AQUA' => '#00FFFF',
'AQUAMARINE' => '#7FFFD4',
'AZURE' => '#F0FFFF',
'BEIGE' => '#F5F5DC',
'BISQUE' => '#FFE4C4',
'BLACK' => '#000000',
'BLANCHED ALMOND' => '#FFEBCD',
'BLUE' => '#0000FF',
'BLUE VIOLET' => '#8A2BE2',
'BROWN' => '#A52A2A',
'BURLY WOOD' => '#DEB887',
'CADET BLUE' => '#5F9EA0',
'CHARTREUSE' => '#7FFF00',
'CHOCOLATE' => '#D2691E',
'CORAL' => '#FF7F50',
'CORN FLOWER BLUE' => '#6495ED',
'CORN SILK' => '#FFF8DC',
'CRIMSON' => '#DC143C',
'CYAN' => '#00FFFF',
'DARK BLUE' => '#00008B',
'DARK CYAN' => '#008B8B',
'DARK GOLDENROD' => '#B8860B',
'DARK GRAY' => '#A9A9A9',
'DARK GREEN' => '#006400',
'DARK KHAKI' => '#BDB76B',
'DARK MAGENTA' => '#8B008B',
'DARK OLIVE GREEN' => '#556B2F',
'DARK ORANGE' => '#FF8C00',
'DARK ORCHID' => '#9932CC',
'DARK RED' => '#8B0000',
'DARK SALMON' => '#E9967A',
'DARK SEA GREEN' => '#8FBC8F',
'DARK SLATE BLUE' => '#483D8B',
'DARK SLATE GRAY' => '#2F4F4F',
'DARK TURQUOISE' => '#00CED1',
'DARK VIOLET' => '#9400D4',
'DEEP PINK' => '#FF1493',
'DEEP SKY BLUE' => '#00BFFF',
'DULL GRAY' => '#696969',
'DODGER BLUE' => '#1E90FF',
'FIRE BRICK' => '#B22222',
'FLORAL WHITE' => '#FFFAF0',
'FOREST GREEN' => '#228B22',
'FUCHSIA' => '#FF00FF',
'GAINSBORO' => '#DCDCDC',
'GHOST WHITE' => '#F8F8FF',
'GOLD' => '#FFD700',
'GOLDENROD' => '#DAA520',
'GRAY' => '#808080',
'GREEN' => '#008000',
'GREEN YELLOW' => '#ADFF2F',
'HONEYDEW' => '#F0FFF0',
'HOT PINK' => '#FF69B4',
'INDIAN RED' => '#CD5C5C',
'INDIGO' => '#4B0082',
'IVORY' => '#FFFFF0',
'KHAKI' => '#F0E68C',
'LAVENDER' => '#E6E6FA',
'LAVENDER BLUSH' => '#FFF0F5',
'LEAF' => '    #6B8E23',
'LEMON CHIFFON' => '#FFFACD',
'LIGHT BLUE' => '#ADD8E6',
'LIGHT CORAL' => '#F08080',
'LIGHT CYAN' => '#E0FFFF',
'LIGHT GOLDENROD YELLOW' => '#FAFAD2',
'LIGHT GREEN' => '#90EE90',
'LIGHT GRAY' => '#D3D3D3',
'LIGHT PINK' => '#FF86C1',
'LIGHT SALMON' => '#FFA07A',
'LIGHT SEA GREEN' => '#20B2AA',
'LIGHT SKY BLUE' => '#87CEFA',
'LIGHT STEEL BLUE' => '#778899',
'LIGHT YELLOW' => '#FFFFE0',
'LIME' => '#00FF00',
'LIME GREEN' => '#32CD32',
'LINEN' => '#FAF0E6',
'MAGENTA' => '#FF00FF',
'MAROON' => '#800000',
'MEDIUM AQUA MARINE' => '#66CDAA',
'MEDIUM BLUE' => '#0000CD',
'MEDIUM ORCHID' => '#BA55D3',
'MEDIUM PURPLE' => '#9370DB',
'MEDIUM SEA GREEN' => '#3CB371',
'MEDIUM SLATE BLUE' => '#7B68EE',
'MEDIUM SPRING BLUE' => '#00FA9A',
'MEDIUM TURQUOISE' => '#48D1CC',
'MEDIUM VIOLET RED' => '#C71585',
'MIDNIGHT BLUE' => '#191970',
'MINT CREAM' => '#F5FFFA',
'MISTY ROSE' => '#FFE4E1',
'NAVAJO WHITE' => '#FFDEAD',
'NAVY' => '#000080',
'OLD LACE' => '#FDF5E6',
'OLIVE' => '#808000',
'ORANGE' => '#FFA500',
'ORANGE RED' => '#FF4500',
'ORCHID' => '#DA70D6',
'PALE GOLDENROD' => '#EEE8AA',
'PALE GREEN' => '#98FB98',
'PALE TURQUOISE' => '#AFEEEE',
'PALE VIOLET RED' => '#DB7093',
'PAPAYAWHIP' => '#FFEFD5',
'PEACH PUFF' => '#FFDAB9',
'PERU' => '#CD853F',
'PINK' => '#FFC0CB',
'PLUM' => '#DDA0DD',
'POWDER BLUE' => '#B0E0E6',
'PURPLE' => '#800080',
'RED' => '#FF0000',
'ROSY BROWN' => '#BC8F8F',
'ROYAL BLUE' => '#4169E1',
'SADDLE BROWN' => '#8B4513',
'SALMON' => '#FA8072',
'SANDY BROWN' => '#F4A460',
'SEA GREEN' => '#2E8B57',
'SEASHELL' => '#FFF5EE',
'SIENNA' => '#A0522D',
'SILVER' => '#C0C0C0',
'SKY BLUE' => '#87CEEB',
'SLATE BLUE' => '#6A5ACD',
'SLATE GRAY' => '#708090',
'SNOW' => '#FFFAFA',
'SPRING GREEN' => '#00FF7F',
'STEEL BLUE' => '#4682B4',
'TAN' => '#D2B48C',
'TEAL' => '#008080',
'THISTLE' => '#D88FD8',
'TOMATO' => '#FF6347',
'TURQUOISE' => '#40E0D0',
'VIOLET' => '#EE82EE',
'WHEAT' => '#F5DEB3',
'WHITE' => '#FFFFFF',
'WHITE SMOKE' => '#F5F5F5',
'YELLOW' => '#FFFF00',
'YELLOW GREEN' => '#9ACD32');
?>

    
[2]php颜色值转换 php实现16进制数字与颜色值的转换
    来源: 互联网  发布时间: 2013-12-24

本节给出的php代码,实现了二个函数,用于将颜色值转换为16进制数字,或将16进制数字转换为颜色值。

例子:
 

代码示例:

<?php
/**
* 颜色值与16进制数字的转换
* edit: WWW.JBXUE.COM
*/
function toHex($N) {
    if ($N==NULL) return "00";
    if ($N==0) return "00";
    $N=max(0,$N);
    $N=min($N,255);
    $N=round($N);
    $string = "0123456789ABCDEF";
    $val = (($N-$N%16)/16);
    $s1 = $string{$val};
    $val = ($N%16);
    $s2 = $string{$val};
    return $s1.$s2;
}

//颜色值转换为16进制数字
function rgb2hex($r,$g,$b){
    return toHex($r).toHex($g).toHex($b);
}
//16进制数字转换为颜色值
function hex2rgb($N){
    $dou = str_split($N,2);
    return array(
        "R" => hexdec($dou[0]),
        "G" => hexdec($dou[1]),
        "B" => hexdec($dou[2])
    );
}

echo rgb2hex(106,48,48);
echo '<p> </p>';
print_r(hex2rgb("6A3030"));
?>


    
[3]php导入csv到MySql数据库的例子
    来源: 互联网  发布时间: 2013-12-24

php导入csv到MySql数据库。
代码:
 

代码示例:

<?php
/**
* 将csv文件导入到mysql数据库
* edit: www.
*/
$databasehost = "localhost";
$databasename = "test";
$databasetable = "sample";
$databaseusername ="test";
$databasepassword = "";
$fieldseparator = ",";
$lineseparator = "\n";
$csvfile = "filename.csv";

/********************************/
/* Would you like to add an ampty field at the beginning of these records?
/* This is useful if you have a table with the first field being an auto_increment integer
/* and the csv file does not have such as empty field before the records.
/* Set 1 for yes and 0 for no. ATTENTION: don't set to 1 if you are not sure.
/* This can dump data in the wrong fields if this extra field does not exist in the table
/********************************/
$addauto = 0;
/********************************/

/* Would you like to save the mysql queries in a file? If yes set $save to 1.
/* Permission on the file should be set to 777. Either upload a sample file through ftp and
/* change the permissions, or execute at the prompt: touch output.sql && chmod 777 output.sql
/********************************/
$save = 1;
$outputfile = "output.sql";
/********************************/

if (!file_exists($csvfile)) {
        echo "File not found. Make sure you specified the correct path.\n";
        exit;
}

$file = fopen($csvfile,"r");

if (!$file) {
        echo "Error opening data file.\n";
        exit;
}

$size = filesize($csvfile);

if (!$size) {
        echo "File is empty.\n";
        exit;
}

$csvcontent = fread($file,$size);

fclose($file);

$con = @mysql_connect()($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(mysql_error());

$lines = 0;
$queries = "";
$linearray = array();

foreach(split($lineseparator,$csvcontent) as $line) {

        $lines++;

        $line = trim($line," \t");

        $line = str_replace()("\r","",$line);

        /************************************
        This line escapes the special character. remove it if entries are already escaped in the csv file
        ************************************/
        $line = str_replace("'","\'",$line);
        /*************************************/

        $linearray = explode()($fieldseparator,$line);

        $linemysql = implode("','",$linearray);

        if($addauto)
                $query = "insert into $databasetable values('','$linemysql');";
        else
                $query = "insert into $databasetable values('$linemysql');";

        $queries .= $query . "\n";

        @mysql_query()($query);
}

@mysql_close($con);

if ($save) {

        if (!is_writable($outputfile)) {
                echo "File is not writable, check permissions.\n";
        }

        else {
                $file2 = fopen($outputfile,"w");

                if(!$file2) {
                        echo "Error writing to the output file.\n";
                }
                else {
                        fwrite($file2,$queries);
                        fclose($file2);
                }
        }

}
echo "在csv文件中共找到多少 $lines 条记录.\n";
?>


    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3