手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:PHP

PHP学习(一)之基本语法

任何一门语言,最重要的往往都是由:基本语法、类型、各种变量常量、表达式、运算符、控制结构、函数(对象、异常处理)等组成。在学习PHP的过程中,我也将逐步为以上的内容的学习作一概要,当然,首推还是手册,基本以介绍手册为主。

» 阅读全文

PHP中str_replace函数的详解 [转 ]

在网上看到这个函数的介绍。虽然这个函数比较简单,且不支持正则,但……这个函数还是相对用的比较多的,自己又比较懒,看到这篇文章,于是就转载一下。

str_replace用的最多的地方恐怕应该是str_replace(array("\r","\n","\r\n"),"<br />" , $content);了,适合添加文章或者其他的时候用,当然这个时候nl2br函数也有用。

原文地址:http://www.phpweblog.net/yemoo/archive/2008/03/15/2971.html

原文作者:Yemoo

» 阅读全文

Tags: 函数

PHP中Eval的作用

eval是什么,相信很多都会知道。但真实有多少人使用它呢?恐怕在实际应用中,使用的也比较少吧。(详细请看全文)

Evaluates the string given in code_str as PHP code. Among other things, this can be useful for storing code in a database text field for later execution.

There are some factors to keep in mind when using eval(). Remember that the string passed must be valid PHP code, including things like terminating statements with a semicolon so the parser doesn't die on the line after the eval(), and properly escaping things in code_str. To mix HTML output and PHP code you can use a closing PHP tag to leave PHP mode.

Also remember that variables given values under eval() will retain these values in the main script afterwards.

» 阅读全文

Tags: php

PHP一些常用的计算时间方法

 

在PHP里面,要想统计一个action或者一个函数或者某个过程的执行所消耗的时间往往都只有一个办法:在运算前记录下时间戳,在运算后记录下时间戳,然后相减,就能得到一个相对比较实际的时间。

基本代码如下(从phpmyadmin里复制而来,懒得打了。这段代码其实也就是phpMyadmin里SQL的执行时间的计算):

PHP代码
  1. <?php   
  2.     // garvin: Measure query time.   
  3.     // TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411   
  4.     $querytime_before = array_sum(explode(' ', microtime()));   
  5.   
  6.     $result   = @PMA_DBI_try_query($full_sql_query, null, PMA_DBI_QUERY_STORE);   
  7.   
  8.     $querytime_after = array_sum(explode(' ', microtime()));   
  9.   
  10.     $GLOBALS['querytime'] = $querytime_after - $querytime_before;   
  11.   
  12. ?>  

 其中 array_sum(explode(' ', microtime())); 是PHP4时代的写法,到PHP5之后,microtime函数多了一个bool值的参数,加上这个参数后可以直接得到 array_sum(explode(' ', microtime())); 相等的值,即:microtime(true);

本文并无技术含量,纯粹用来记录一下。

Tags: 计算时间

JpGraph中文乱码完美解决方案[转]

原文地址:http://lizi.blogbus.com/logs/12601515.html

 

XML/HTML代码
  1. 很多人使用JpGraph会出现乱码问题,但是网上有好多并无效果的解决方式,经过反复试验及在网上看了其它人的经验,总结出在2.3版下最终较完美解决方案   
  2. 1、把simsun.ttc字体拷到服务器/usr/X11R6/lib/X11/fonts/truetype下,当然这个目录可以自定义   
  3. 2、不需要更改$aFF === FF_SIMSUN或$aFF === FF_CHINESE ,直接用以下代码即可   
  4. $title = "JpGraph中文测试";   
  5. $title = iconv("UTF-8", "gb2312", $title);   
  6. $graph->title->Set($title);   
  7. 就可以完美的解决中文问题了   
  8. 3、还有一个问题,就是右上方的中文显示问题,就是SetLegend函数,解决方式如下   
  9. 打开jpgraph.php文件,找到   
  10. private $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12;   
  11. 用   
  12. private $font_family=FF_SIMSUN,$font_style=FS_NORMAL,$font_size=8;   
  13. 替换就OK了^_^  

后记:本来都忘了这个了,正好有朋友问起类似的问题,于是又GOOGLE了一下,找到了这个,记录一下,也为GOOGLE的收录作点贡献,这样以后再有人遇到类似问题,更容易被搜索到。