php 提交数据并且保存符合php编码的文件实例

 更新时间:2016年11月25日 15:57  点击:2028

if( $_POST )
{

 $str = '23=12,34  78=1,3 45=12,46,78,89=33'; 

 $content=nl2br($str); 

 $content=str_replace(" ","",$content); 

 $arr=explode("<br/>",$content); 

 $result=array(); 

 foreach ($arr as $value) 

 { 

$k=explode("=",$value); 

 $result[]=array($k[0]=>$k[1]); 

 } 

 //数组转换成字串 

 function arrayeval($array, $level = 0) { 

  $space = ''; 

  for($i = 0; $i <= $level; $i++) { 

  $space .= " "; 

  } 

 $evaluate = "Array $space( "; 

  $comma = $space; 

  foreach($array as $key => $val) { 

   $key = is_string($key) ? '''.addcslashes($key, ''\').''' : $key; 

   $val = !is_array($val) && (!preg_match("/^-?d+$/", $val) || strlen($val) > 12 || substr($val, 0, 1)=='0') ? '''.addcslashes($val, ''\').''' : $val; 

   if(is_array($val)) { 

    $evaluate .= "$comma$key => ".arrayeval($val, $level + 1); 

  } else { 

    $evaluate .= "$comma$key => $val"; 

   } 

   $comma = ", $space"; 

  } 

 $evaluate .= " $space)"; 

  return $evaluate; 

 } 

//把结果写到文件 

 $config=arrayeval($result); 

 $strwrite="<?php ".'$'.'shuzu'.'='.$config." ?>"; 

 $fp=fopen('config.php','w'); 

 fwrite($fp,$strwrite); 

 fclose($fp); 
 }

 ?>

<form action="b.php?action=5" method="get"> 

<textarea name="content"></textarea> 

<input type="submit" value="submit" /> 

</form>

传值方法很多,
参数传值: 可以是urs.php?id=1带参数形式,这是页面之间比较主要的传值方式 ,用request,get 接收值.
from表单传值 : 主要接收request传值 post, get  来接收,from标签可以选择get或者post 通过url传值的是get 还可以利用ajax传值可以选择post或者get.

session传值 : 这个一般是做用户登陆时用的,服务器全局变量,一般不用在页面之前的传值
cookie传值 :把内容保存在客户端,

我们常用的页面传值主要是参数传值  from表单传值传值。

现在来做几个实例
*/
//先用页面参数传值实例

?>

<a href="b.php?action=1">点击我</a>
//输出值为 1

用form传值

<form action="b.php" method="get"> 

<input name="action" type="text" value="5">

<input type="submit" value="submit" /> 

</form>

得出值 5

<form action="b.php" method="POST"> 

<input name="action" type="text" value="5">

<input type="submit" value="submit" /> 

</form>


<?
if( $_GET )
{
 echo 'get传值',$_GET['action'];
}
else
{
 echo 'post传值', $_POST['action'];
}
//本文章原创于www.111cn.net 中国WEB第一站,,转载注明出处

缓存的工作原理其实并不复杂。它的核心思想是:首先,我们将需要显示的内容存储在一个文本文件(即缓存文件)之中。然后,如果有用户请求某个页面的内容,我们首先检查此页对应的缓存(即那个文本文件)是否存在——如果存在且为最新的缓存文件,那么直接将这个文本文件中的内容输出到客户端供用户查看;如果此页对应的缓存文件不存在或缓存生成的时间不符合要求(太旧),那么直接执行一次此页对应的PHP文件,并将显示内容存储在缓存文件中。重复上述流程。这样一来,虽然增加了PHP代码,但我们最大程度的节省了PHP链接到数据库教程再提取数据的时间。

*/

   //导入缓存类
   require_once('cache.class.php教程');
   //创建一个缓存类对象CacheManager
   $CacheManager = new Cache();
   //调用startCache方法,表示开始缓存
   $CacheManager->startCache();
   //以下区块所有echo内容都将作为缓存写入缓存文件中
   echo "Start Cache example at: ".date('H:i:s')."<br/>";
   sleep(2);
   echo "End Cache example at: ".date('H:i:s')."<br/>";
  
   echo "<br/><a href='clear.php'>Clean the cache</a><br/>";
   //以上区块所有echo内容都将作为缓存写入缓存文件中
   $CacheManager->endCache();


//cache.class.php代码

class Cache {
   var $status    = true;     // 值为True表示开启缓存;值False表示关闭缓存功能。
   var $cacheDir  = 'cache/'; //存放缓存文件的默认目录
   var $cacheFile = '';       //缓存文件的真实文件名
   var $timeOut   = 1000;     // 内容被重复使用的最长时限
   var $startTime = 0;        // 程序执行的开始时间
   var $caching     = true;     // 是否需要对内容进行缓存;值为False表示直接读取缓存文件内容
  
   function getMicroTime() {
           list($usec, $sec) = explode(" ",microtime());
          return ((float)$usec + (float)$sec);
    }

function startCache(){
      $this->startTime = $this->getMicroTime();
      ob_start();
      if ($this->status){
         $this->cacheFile = $this->cacheDir.urlencode( $_SERVER['REQUEST_URI'] );
         if ( (file_exists($this->cacheFile)) &&
              ((fileatime($this->cacheFile) + $this->timeOut) > time()) )
         {
            //从缓存文件中读取内容
            $handle = fopen($this->cacheFile , "r");
            $html   = fread($handle,filesize($this->cacheFile));
            fclose($handle);
         
            // 显示内容
            echo $html;

            // 显示程序执行时间          
           echo '<p>Total time: '
                 .round(($this->getMicroTime())-($this->startTime),4).'</p>';
           
            //退出程序
            exit();
          }
          else
          {
             //置缓存标志caching为true
             $this->caching = true;
          }
      }
    }

function endCache(){
      if ($this->status){
         if ( $this->caching )
         {
            //首先输出页面内容,然后将输出内容保存在缓存文件中
            $html = ob_get_clean();
            echo $html;
            $handle = fopen($this->cacheFile, 'w' );
            fwrite ($handle, $html );
            fclose ($handle);

            //显示页面执行时间           
            echo '<p>Total time: '.round(($this->getMicroTime()-$this->startTime),4).'</p>';
         }
      }      
    }

function cleanCache(){
       if ($handle = opendir($this->cacheDir)) {
          while (false !== ($file = readdir($handle))) {
             if (is_file($this->cacheDir.$file)) unlink($this->cacheDir.$file);
          }

          closedir($handle);      
       }
    }

}


// 再一个简单的php  缓存文件实例代码


if ($content = $cache->start($cache_id))
{
 echo $content;
 exit();
}

require_once 'Cache/Function.php';
 

 $cacheDir = './pear_cache/';
 $cache = new Cache_Function('file',array('cache_dir' => $cacheDir));
 $arr = array('东方', '南方','西方');
 $cache->call('slowFunction', $arr);
 echo '<BR>';

 $arr = array('东方', '南方','西方');

 slowFunction($arr);

  function slowFunction($arr = null)
 {
  echo "一个执行起来很慢的函数 :( <br>";
  echo "当前时间是 " . date('M-d-Y H:i:s A', time()) . '<br>';
  foreach ($arr as $fruit)
  {
   echo "太阳此时正在 $fruit <br>";
  }
 )

述前说明:
CREATE VIEW 语句时,ANSI_NULLS 和 QUOTED_IDENTIFIER 选项必须设置为 ON。OBJECTPROPERTY 函数通过 ExecIsAnsiNullsOn 或 ExecIsQuotedIdentOn 属性为视图报告此信息

表a,字段a1,a2
表b,字段b1,b2
要弄个视图union all两个表

$sql ='CREATE VIEW dbo.VIEW2
  AS
  SELECT * FROM a
  UNION ALL
  (SELECT * FROM b )';
  

上面的是简单的创建视图并没有索引下面我们来看看关于创建索引视图

对指定表或指定表的视图创建关系索引。可在向表中填入数据前创建索引。可通过指定限定的数据库教程名称对另一个数据库中的表或视图创建关系索引。
语法:

CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
    ON <object> ( column_name [ ASC | DESC ] [ ,...n ] )
    [ WITH <backward_compatible_index_option> [ ,...n ] ]
    [ ON { filegroup_name | "default" } ]

<object> ::=
{
    [ database_name. [ owner_name ] . | owner_name. ]
        table_or_view_name
}

<backward_compatible_index_option> ::=
{
    PAD_INDEX
  | FILLFACTOR = fillfactor
  | SORT_IN_TEMPDB
  | IGNORE_DUP_KEY
  | STATISTICS_NORECOMPUTE
  | DROP_EXISTING
}


//--创建视图  
  create   view   v  
  with   schemabinding  
  as  
  select   ID,name   from   dbo.A  
  go  
   
//  --创建索引  
  create   unique   clustered   index   v_index   on   v(ID)

php教程 发送邮箱实例代码


class pop3 {


        public $server="pop3.126.com";//服务器名
        public $server_port=110;//服务器端口
        public $timeout=30;//超过多少时间就算连接失败
        public $connection=0;//保持与主机的连接
        public $state="DISCONNECTED";//保存当前的状态  
        public $debug=0;//是否显示错误信息
        public $err_str="";//服务器返回的错误信息
        public $err_no;//服务器返回的错误号
        public $respones;//保存服务器返回的信息
        public $apop;//说明需要使用加密方式进行密码验证
        public $messages;//邮件数
        public $size;//邮件的总大小
        public $mail_list;//保存各个邮件的大小及在服务器上的序列号
        public $head=array();//邮件头的内容数组
        public $body=array();//邮件体的内容数组 


        function POP3($server,$server_port,$timeout)
        {
                $this->server=$server;
                $this->server_port=$server_port;
                $this->timeout=$timeout;
                $this->debug=TRUE;
        }

        function open()
        {
                if($this->server=="")
                {
                        $this->err_str="无效的主机名!";
                        return FALSE;
                }
                if($this->debug)  echo "正在打开  $this->server,$this->server_port,$this->timeout";
                if(!$this->connection=@fsockopen($this->server,$this->server_port,$err_no,$err_str,$this->timeout))
                {
                        $this->err_str="连接到POP服务器失败,错误信息:".$err_str."错误号:".$err_no;
                        return FALSE;
                }
                else
                {
                        $this->getresponse();
                        if($this->debug)
                            $this->outdebug($this->response);
                        if(substr($this->respones,0,3)!="+OK")
                        {
                                $this->err_str="服务器返回无效信息:".$this->respones."请检查pop服务器是否正确";
                                return FALSE;
                        }
                        $this->state="AUTHORIZATION";
                        return TRUE;
                }
        }

        function getresponse()
        {
                for($this->respones;;)
                {
                        if(feof($this->connection))
                            return FALSE;
                        $this->respones.=fgets($this->connection,100);
                        $length=strlen($this->respones);
                        if($length>=2&&substr($this->respones,$length-2,2)=="rn")
                        {
                                $this->respones=strtok($this->respones,"rn");
                                return TRUE;
                        }
                }
        }

        function outdebug($message)
        {
                echo htmlspecialchars($message)."n";
        }

        function command($command,$length,$code)
        {
                if($this->connection==0)
                {
                        $this->outdebug("没有连接到任何服务器,请检查网络连接!");
                        return FALSE;
                }
                if($this->debug)
                    $this->outdebug(">>> $command");
                if(!fput($this->connection,"$command rn"))
                {
                        $this->outdebug("'无法发送命令'.$command");
                        return FALSE;
                }
                else
                {
                        $this->getresponse();
                        if($this->debug)
                           $this->outdebug($this->respones);
                        if(substr($this->respones,0,$length)!=$code)
                        {
                                $this->outdebug("$command.'命令服务器返回信息无效'.$this->response");
                                return FALSE;
                        }
                        else
                            return TRUE;
                }
        }

        function login($user,$pass)
        {
                if($this->state!="AUTHORIZATION")
                {
                        $this->outdebug("没有连接到任何服务器或状态不对!");
                        return FALSE;
                }
                if(!$this->apop)
                {
                        if(!$this->command("USER $user",3,"+OK"))  return FALSE;
                        if(!$this->command("PASS $pass",3,"+OK"))  return FALSE;
                }
                else
                {
                        if(!$this->command(" APOP $user".md5($this->greeting.$pass),3,"+OK"))  return FALSE;
                }
                $this->state="TRANSACTION";
                return TRUE;
        }

        function stat_sum()
        {
                if($this->state!="TRANSACTION")
                {
                        $this->outdebug("还没有连接服务器或没有成功登陆");
                        return FALSE;
                }
                if(!$this->command("STAT",3,"+OK"))
                    return FALSE;
                else
                {
                        $this->respones=strtok($this->respones," ");
                        $this->messages=strtok(" ");
                        $this->size=strtok(" ");
                        return TRUE;
                }
        }

        function listmail($mess=null,$uni_id=null)
        {
                if($this->state!="TRANSACTION")
                {
                        $this->outdebug("还没有连接服务器或没有成功登陆");
                        return FALSE;
                }
                if($uni_id)
                   $command="UIDL";
                else
                   $command="LIST";
                if($mess)
                   $command.=$mess;
                if(!$this->command($command,3,"+OK"))
                   return FALSE;
                else
                {
                        $i=0;
                        $this->mail_list=array();
                        $this->getresponse();
                        while($this->respones!=".")
                        {
                                $i++;
                                if($this->debug)
                                   $this->outdebug($this->respones);
                                if(uni_id)
                                {
                                        $this->mail_list[$i][num]=strtok($this->respones," ");
                                        $this->mail_list[$i][size]=strtok(" ");
                                }
                                else
                                {
                                        $this->mail_list[$i][num]=intval(strtok($this->respones," "));
                                        $this->mail_list[$i][size]=intval(strtok(" "));
                                }
                                $this->getresponse();
                        }
                        return TRUE;
                }
        }

        function getmail($num,$line=-1)
        {
                if($this->state!="TRANSACTION")
                {
                        $this->outdebug("还没有连接服务器或没有成功登陆");
                        return FALSE;
                }
                if($line<0)
                   $command="RETR $num";
                else
                   $command="TOP $num $line";
                if(!$this->command($command,3,"+OK"))
                   return FALSE;
                else
                {
                        $this->getresponse();
                        $is_head=TRUE;
                        while($this->respones!=".")
                        {
                                if($this->debug)
                                   $this->outdebug($this->respones);
                                if(substr($this->respones,0,1)!=".")
                                {
                                        $this->respones=substr($this->respones,1,strlen($this->respones)-1);
                                }
                                if(trim($this->respones)=="")
                                    $is_head=FALSE;
                                if($is_head)
                                   $this->head[]=$this->respones;
                                else
                                   $this->body[]=$this->respones;
                                $this->getresponse();
                        }
                        return TRUE;
                }
        }

        function dele($num)
        {
                if($this->state!="TRANSACTION")
                {
                        $this->outdebug(",不能删除远程信件,还没有连接服务器或没有成功登陆");
                        return FALSE;
                }
                if(!num)
                {
                        $this->outdebug("删除的邮件参数不对");
                        return FALSE;
                }
                if($this->command("DELE $num",3,"+OK")) return TRUE;
                else return FALSE;
        }

        function close()
        {
                if($this->connection!=0)
                {
                        if($this->state=="TRANSACTION")
                           $this->command("QUIT",3,"+OK");
                        fclose($this->connection);
                        $this->connection==0;
                        $this->state="DISCONNECTED";
                }
        }
}

//发送邮件类调用方法

$host="pop3.126.com";
    $user="    ";
    $pass="     ";
    $rec=new pop3($host,110,20);
    if(!$rec->open()) die($rec->err_str);
       echo "open";
    if(!$rec->login($user,$pass)) die($rec->err_str);
       echo "login";
    if(!$rec->stat()) die($rec->err_str);
       echo "共有".$rec->messages."封信件,共".$rec->size."字节大小";
    if($rec->messages>0)
    {
            if(!$rec->listmail()) die($rec->err_str);
               echo "有以下信件:";
            for($i=1;$i<=count($rec->mail_list);$i++)
            {
                    echo "信件".$rec->mail_list[$i][num]."大小".$rec->mail[$i][size]."";
            }
            $rec->getmail(1);
            echo "邮件头的内容:";
            for($i=0;$ihead;$i++)
               echo htmlspecialchars($rec->head[$i])."n";
            for($i=0;$ibody;$i++)
               echo htmlspecialchars($rec->body[$i])."n";
    }
    $rec->close();

[!--infotagslink--]

相关文章

  • php读取zip文件(删除文件,提取文件,增加文件)实例

    下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
  • Jupyter Notebook读取csv文件出现的问题及解决

    这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06
  • Photoshop打开PSD文件空白怎么解决

    有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
  • 解决python 使用openpyxl读写大文件的坑

    这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
  • C#实现HTTP下载文件的方法

    这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • SpringBoot实现excel文件生成和下载

    这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
  • C#操作本地文件及保存文件到数据库的基本方法总结

    C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
  • php无刷新利用iframe实现页面无刷新上传文件(1/2)

    利用form表单的target属性和iframe 一、上传文件的一个php教程方法。 该方法接受一个$file参数,该参数为从客户端获取的$_files变量,返回重新命名后的文件名,如果上传失...2016-11-25
  • php批量替换内容或指定目录下所有文件内容

    要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
  • PHP文件上传一些小收获

    又码了一个周末的代码,这次在做一些关于文件上传的东西。(PHP UPLOAD)小有收获项目是一个BT种子列表,用户有权限上传自己的种子,然后配合BT TRACK服务器把种子的信息写出来...2016-11-25
  • JS中artdialog弹出框控件之提交表单思路详解

    artDialog是一个基于javascript编写的对话框组件,它拥有精致的界面与友好的接口。本文给大家介绍JS中artdialog弹出框控件之提交表单思路详解,对本文感兴趣的朋友一起学习吧...2016-04-19
  • Zend studio文件注释模板设置方法

    步骤:Window -> PHP -> Editor -> Templates,这里可以设置(增、删、改、导入等)管理你的模板。新建文件注释、函数注释、代码块等模板的实例新建模板,分别输入Name、Description、Patterna)文件注释Name: 3cfileDescriptio...2013-10-04
  • AI源文件转photoshop图像变模糊问题解决教程

    今天小编在这里就来给photoshop的这一款软件的使用者们来说下AI源文件转photoshop图像变模糊问题的解决教程,各位想知道具体解决方法的使用者们,那么下面就快来跟着小编...2016-09-14
  • C++万能库头文件在vs中的安装步骤(图文)

    这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
  • php文件上传你必须知道的几点

    本篇文章主要说明的是与php文件上传的相关配置的知识点。PHP文件上传功能配置主要涉及php.ini配置文件中的upload_tmp_dir、upload_max_filesize、post_max_size等选项,下面一一说明。打开php.ini配置文件找到File Upl...2015-10-21
  • ant design中upload组件上传大文件,显示进度条进度的实例

    这篇文章主要介绍了ant design中upload组件上传大文件,显示进度条进度的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-29
  • C#使用StreamWriter写入文件的方法

    这篇文章主要介绍了C#使用StreamWriter写入文件的方法,涉及C#中StreamWriter类操作文件的相关技巧,需要的朋友可以参考下...2020-06-25
  • php实现文件下载实例分享

    举一个案例:复制代码 代码如下:<?phpclass Downfile { function downserver($file_name){$file_path = "./img/".$file_name;//转码,文件名转为gb2312解决中文乱码$file_name = iconv("utf-8","gb2312",$file_name...2014-06-07
  • C#路径,文件,目录及IO常见操作汇总

    这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • 查找php配置文件php.ini所在路径的二种方法

    通常php.ini的位置在:复制代码 代码如下:/etc目录下或/usr/local/lib目录下。如果你还是找不到php.ini或者找到了php.ini修改后不生效(其实是没找对),请使用如下办法:1.新建php文件,写入如下代码复制代码 代码如下:<?phpe...2014-05-31