当前位置:  编程技术>php
本页文章导读:
    ▪php绘图技术的例子      1、图片格式: 常见图片格式,包括:gif,jpg/jpeg,png等。 区别: 1)、gif 图片压缩率高,但是只能显示256色,可能造成颜色的丢失,可以显示动画。 2)、jpg/jpeg 图片压缩率高(有损压缩),可.........
    ▪php xml编程之词库练习实例      PHP 操作xml编程的例子,对词库的练习,学习对xml文件的增、删、改、查的操作。 1、wordView.php   代码示例: <html> <head>     <meta http-equiv="Content-type" content="text/html;charset=utf-8"> .........
    ▪ajax检查用户名是否注册的实例代码(图文)      1,用户注册页面 register.php   代码示例: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>   <head>     <title>用户注册---www.</title>     <meta http-equiv="pragma" con.........

[1]php绘图技术的例子
    来源: 互联网  发布时间: 2013-12-24

1、图片格式:
常见图片格式,包括:gif,jpg/jpeg,png等。

区别:
1)、gif 图片压缩率高,但是只能显示256色,可能造成颜色的丢失,可以显示动画。
2)、jpg/jpeg 图片压缩率高(有损压缩),可以用较小的文件来显示。
3)、png 该格式综合了gif和jpg的优势,缺点是不能显示动画。

2、PHP绘图实例

<?php
//绘图技术 基本步骤 前提:在php.ini文件中启用gd库

//创建画布 默认背景是黑色的
$img=imagecreatetruecolor(400,300);

//绘制各种图形
//创建一个颜色
$background = imagecolorallocate($img, 255, 0, 0);
//画圆
//imageellipse($img,30,30,50,50,$background);
//椭圆
//imageellipse($img,30,30,50,30,$background);
//画直线
//imageline($img,0,0,400,300,$background);
//画矩形
//imagerectangle ($img, 50 , 20 , 100 , 40 , $background);
//填充矩形
//imagefilledrectangle ($img, 50 , 20 , 100 , 40 , $background);
//画弧线
//imagearc($img, 100, 100, 150, 150, 180, 270, $background);
//画扇型  IMG_ARC_CHORD直线连接了起始和结束点   IMG_ARC_PIE
//imagefilledarc($img, 100, 100, 150, 150, 180, 270, $background,IMG_ARC_PIE);

//拷贝图片到画布
/*$scrImg=imagecreatefromgif('http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');
$scrImgInfo=getimagesize('http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');
imagecopy ($img,$scrImg,10,10,0,0,$scrImgInfo[0],$scrImgInfo[1]);
*/
//imagecopy ($img,$scrImg,10,10,0,0,270,129);

//写字
//imagestring ($img , 5 , 20 , 20 , "hello,world", $background );
//写中文
$str="PHP绘画技术";
imagettftext ($img , 30 , 0 , 50 ,50, $background , "MSYHBD.TTF" , $str);

//输出图像到网页(或者另存为)
header("content-type: image/png");
imagepng($img);

//销毁该图片(释放内存)
imagedestroy($img);
?>

    
[2]php xml编程之词库练习实例
    来源: 互联网  发布时间: 2013-12-24

PHP 操作xml编程的例子,对词库的练习,学习对xml文件的增、删、改、查的操作。

1、wordView.php
 

代码示例:
<html>
<head>
    <meta http-equiv="Content-type" content="text/html;charset=utf-8">
</head>
<body>
    <form action="/blog_article/wordProcess.html" method="post">
        <input type="text" name="enword">
        <input type="hidden" name="type" value="query">
        <input type="submit" value="查询">
    </form>
    <span>添加单词</span>
    <form action="/blog_article/wordProcess.html" method="post">
        英文:<input type="text" name="enword"><br>
        中文:<input type="text" name="zhword"><br>
        <!--<input type="hidden" name="type" value="insert">
        <input type="hidden" name="type" value="update"> -->
        <input type="submit" name="type" value="添加">
        <input type="submit" name="type" value="修改">
    </form>
    <form action="/blog_article/wordProcess.html" method="post">
        <input type="text" name="word">
        <input type="hidden" name="type" value="delete">
        <input type="submit" value="删除">
    </form>
</body>
</html>

2、wordProcess.php
 

代码示例:

<?php
    //接收类型 看看用户做什么(查询、添加....)
    $type=$_REQUEST['type'];
    //echo $type;
    //exit();
    //创建xml文档对象
    $doc=new DOMDocument();
    $doc->load("words.xml");

    //进行判断
    if($type=="query"){
        //获取用户输入的值
        $enword=$_REQUEST['enword'];
       
        //判断是否进入查询
        $isEnter=false;
        //获取所有单词节点
        $words=$doc->getElementsByTagName("word");
        //遍历单词节点
        for($i=0;$i<$words->length;$i++){
            $word_node=$words->item($i);
            //获取不同的语种
            $en_word=getNodeVal($word_node,"en");
            $zh_word=getNodeVal($word_node,"zh");
            //查询
            if($enword==$en_word){
                $isEnter=true;
                echo $enword."的中文意思是:".getNodeVal($word_node,"zh");
                echo "<br/><a href='/blog_article/wordView.html'>返回继续查询</a>";
            }else if($enword==$zh_word){
                $isEnter=true;
                echo $enword."的英文意思是:".getNodeVal($word_node,"en");
                echo "<br/><a href='/blog_article/wordView.html'>返回继续查询</a>";
            }
        }

        if(!$isEnter){
            echo "无法查询";
            echo "<br/><a href='/blog_article/wordView.html'>返回继续查询</a>";
        }
    }else if($type=="添加"){
        //接收
        $enword=$_REQUEST['enword'];
        $zhword=$_REQUEST['zhword'];
        if(!empty($enword)&&!empty($zhword)){   
            //获取根节点
            $root=$doc->getElementsByTagName("words")->item(0);
           
            $word=$doc->createElement("word");
            $en=$doc->createElement("en",$enword);
            $zh=$doc->createElement("zh",$zhword);

            //进行挂载

            $root->appendChild($word);
            $word->appendChild($en);
            $word->appendChild($zh);

            //保存xml文件
            $doc->save("words.xml");
            echo "添加成功<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
        }else{
           
            echo "请输入单词";
            echo "<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
            exit();
        }
    }else if($type=="delete"){
       
        $word=$_REQUEST['word'];
        //获取所有单词节点
        $words=$doc->getElementsByTagName("word");
        $isEnter=false;
        //遍历单词节点
        for($i=0;$i<$words->length;$i++){
            $word_node=$words->item($i);
            //获取不同的语种
            $en_word=getNodeVal($word_node,"en");
            $zh_word=getNodeVal($word_node,"zh");
            //查询
            if($word==$en_word || $word==$zh_word){
                $isEnter=true;
                //找到父节点
                $word_node->parentNode->removeChild($word_node);
                $doc->save("words.xml");
                echo "删除成功<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
            }
        }

        if(!$isEnter){
            echo "操作失败";
            echo "<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
        }
    }else if($type="修改"){
        //接收
        $enword=$_REQUEST['enword'];
        $zhword=$_REQUEST['zhword'];
        if(!empty($enword)&&!empty($zhword)){   
            //获取所有单词节点
            $words=$doc->getElementsByTagName("word");
            //遍历单词节点
            $isEnter=false;
            for($i=0;$i<$words->length;$i++){
                $word_node=$words->item($i);
                //获取不同的语种
                $en_word=getNodeVal($word_node,"en");
                $zh_word=getNodeVal($word_node,"zh");
                //查询
                if($enword==$en_word && $zhword!=$zh_word){
                    //修改中文
                    $isEnter=true;
                    //获取zh节点
                    $zh=$word_node->getElementsByTagName("zh")->item(0);
                    $zh->nodeValue=$zhword;
                    $doc->save("words.xml");
                    echo "修改成功";
                    echo "<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
                }else if($enword!=$en_word && $zhword==$zh_word){
                    //修改因为
                    $isEnter=true;
                    $en=$word_node->getElementsByTagName("en")->item(0);
                    $en->nodeValue=$enword;
                    $doc->save("words.xml");
                    echo "修改成功";
                    echo "<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
                }   
            }

            if(!$isEnter){
                echo "没有做任何修改";
                echo "<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
            }

        }else{
            echo "请输入需要修改的单词";
            echo "<br/><a href='/blog_article/wordView.html'>返回继续操作</a>";
            exit();
        }
    }
   
    //获取节点的文本值
    function getNodeVal(&$MyNode,$tagName){
        return $MyNode->getElementsByTagName($tagName)->item(0)->nodeValue;
    }
?>

3、words.xml
 

代码示例:
<?xml version="1.0" encoding="utf-8"?>
<words><word><en>boy</en><zh>男孩</zh></word><word><en>girl</en><zh>女孩</zh></word><word><en>fire</en><zh>火</zh></word><word><en>word</en><zh>词库</zh></word></words>

    
[3]ajax检查用户名是否注册的实例代码(图文)
    来源: 互联网  发布时间: 2013-12-24

1,用户注册页面 register.php
 

代码示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户注册---www.</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">   
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <!--
    <link rel="stylesheet" type="text/css" href="/blog_article/styles.css">
    -->
<script type="text/javascript">   
    //创建ajax引擎
    function getXMLHttpRequest(){
        var xmlHttp;
        if(window.ActiveXObject){
            // Internet Explorer
            xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
        }else{
            // Firefox, Opera 8.0+, Safari
            xmlHttp= new XMLHttpRequest();
        }

        return xmlHttp;
    }
   
    //验证用户
    var xmlHttpRequest;
    function checkUser(){
        xmlHttpRequest=getXMLHttpRequest();
        //清除缓存 get 方式提交
/* var url="/ajax/registerProcess.php?time="+new Date()+"&username="+$("username").value;
   //var url="/ajax/registerProcess.php?username="+$("username").value;
   xmlHttpRequest.open("get",url,true);
   //触发器
   xmlHttpRequest.onreadystatechange=check;
   xmlHttpRequest.send(null);
*/       
   //post 方式提交
   var url="/ajax/registerProcess.php";
   var data="username="+$("username").value;
   xmlHttpRequest.open("post",url,true);
   //post请求需要加入这句
   xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   //触发器
   xmlHttpRequest.onreadystatechange=check;
   xmlHttpRequest.send(data);
}

    //回调函数
    function check(){
        if(xmlHttpRequest.readyState==4){
            if(xmlHttpRequest.status=='200'){
                //window.alert("OK");
                //window.alert("返回用户名"+xmlHttpRequest.responseText);
                //$("myres").value=xmlHttpRequest.responseText;

                //返回是个对象
                /* //处理xml数据
                //window.alert(xmlHttpRequest.responseXML);
                var mes=xmlHttpRequest.responseXML.getElementsByTagName("mes");
                var mes_val=mes[0].childNodes[0].nodeValue;
                $("myres").value=mes_val;
                */
                //处理json数据 使用eval()函数把返回的字符串转成对应的对象
                var mes=xmlHttpRequest.responseText;
                var mes_obj=eval("("+mes+")");
                //window.alert(mes_obj);
                $("myres").value=mes_obj.res;

            }
        }
    }
    //获取dom对象
    function $(id){
        return document.getElementById(id);
    }
</script>
  </head> 
  <body>
    <form action="/blog_article/.html" method="post">
    用户名字:<input type="text"  name="username1" id="username"><input type="button" onclick="checkUser();" value="验证用户名">
    <input type="text" id="myres">
    <br/>
    用户密码:<input type="password" name="password"><br>
    电子邮件:<input type="text" name="email"><br/>
    <input type="submit" value="用户注册">
    </form>
  </body>
</html>

2,接收用户注册信息 registerProcess.php
 

代码示例:

<?php
    //告诉浏览器返回的数据是xml格式
    //header("Content-Type: text/xml;charset=utf-8");
    //告诉浏览器返回的数据是文本格式
    header("Content-Type: text/html;charset=utf-8");
    //告诉浏览器不要缓存数据
    header("Cache-Control: no-cache");

    //接收
    //$username=$_GET['username'];
    $username=$_POST['username'];
   
    $info="";
    if($username=="test1"){
        //echo "用户已注册";
        //$info.="<res><mes>用户名已注册</mes></res>";
        $info='{"res":"用户名已注册"}';
    }else{
        //echo "可以注册";
        //$info.="<res><mes>可以注册</mes></res>";
        $info='{"res":"可以注册"}';
    }
    echo $info;
?>
 

演示效果图:


    
最新技术文章:
▪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