1.php数组基础:
<?php
$ary2 = "zqhung_hongzequan_zqhong";
$arr3 =explode("_",$ary2);//拆分字符串
echo $arr3[1];//打印出来的结果是hongzequan
$ary1 = array("aa","bb");
$ary1[0]="zqhung";//修改数组中的值
echo $ary1[0],"<br>";//打印出来的结果是zqhung
$ary3 = array("id"=>55);
$aa = is_array($ary1);//判断变量是否为数组
echo $aa,"<br>";
echo count($ary1),"<br>";//判断数组中元素的个数
foreach($arr3 as $key=>$value)//遍历数组中的元素
{
echo $value,"<br>";
}
?>
2.连接mysql
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("连接失败");//连接mysql
mysql_select_db("quanquanfly", $conn) or die("连接失败");//连接quanquanfly数据库
$sql = "insert into aa (name,age) value ('1','2')";
mysql_query($sql, $conn);//执行插入操作
/**
* 执行查询并显示操作
*/
$sql1 = "select * from aa";
$query = mysql_query($sql1,$conn);
$select = mysql_fetch_array($query);
while ($select = mysql_fetch_array($query)) {
echo ......
安装 Nginx
* 一条命令搞定:
USE=fastcgi emerge nginx
* 新建用户和组:
groupadd www
useradd www -g www
Nginx 安装好后默认会添加 nginx 组和 nginx 用户,不过我本身还是习惯新建个 www 组和 www 用户来做 HTTP 服务用户。若今后 HTTP 服务器更换为 apache 或是 lighttpd 时,用户名和用户组可以不变。
安装 MySQL
在装 PHP 前必须先装 MySQL,因为 PHP 里的 MySQL 操作函数需要 MySQL 头文件和库的支持。
mysql_install_db --basedir=/usr --datadir=/work/db/3306/data --user=mysql
mkdir -p /work/db/3306/data
mysql_install_db
* 修改配置文件:
vim /etc/mysql/my.cnf
将 datadir 修改为:
datadir = /work/db/3306/data
* 启动 MySQL:
/etc/init.d/mysql start
* 修改 root 密码:
mysqladmin -uroot password hily
* 测试数据库:
mysql -uroot -p
显示:
gentoo setup # mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.84-log Gentoo Linux mysql-5.0.84-r1
Type 'help;' or '\h' for help. Type '\c' to clear the curr ......
<?php
class DoubleQueue
{
public $queue = array();
/**(尾部)入队 **/
public function push($value)
{
return array_push($this->queue,$value);
}
/**(尾部)出队**/
public function pop()
{
return array_pop($this->queue);
}
/**(头部)入队**/
public function enq($value)
{
return array_unshift($this->queue,$value);
}
/**(头部)出队**/
public function deq()
{
return array_shift($this->queue);
}
/**清空队列**/
public function makeEmpty()
{
return unset($this->queue);
}
}
class DoubleDueue
{
public $queue = array();
public function push($value)
{
return $this->queue[] = $value;
}
public function pop()
{
$count = $this->count();
if($count >= 1)
{
$value = $this->queue[$count-1] ......
知道差距了,努力吧!
1. Which of the following will not add john to the users array?
1. $users[] = 'john';
2. array_add($users,'john');
3. array_push($users,'john');
4. $users ||= 'john';
2. What's the difference between sort(), asort() and ksort? Under what circumstances would you use each of these?
3. What would the following code print to the browser? Why?
$num = 10;
function multiply(){
$num = $num * 10;
}
multiply();
echo $num;
4. What is the difference between a reference and a regular variable? How do you pass by reference & why would you want to?
5. What functions can you use to add library code to the currently running script?
6. What is the difference between foo() & @foo()?
7. How do you debug a PHP application?
8. What does === do? What's an example of something that will give true for '==', but not '==='?
9. How would you declare a class named “myclass” with no methods or properties?
10. How wo ......
比如要给用户报告一个错误,用下面的方法:
使用set_error_handler设置自己的错误处理函数,在报错的地方使用trigger_error,在自定义的错误处理函数中给用户显示一个出错信息页面。
但
是如果调用trigger_error的这个页面是被一次ajax请求触发的,那么ajax返回后将得到一大堆用于显示错误的html代码。而一般
ajax调用都会约定自己的错误信息格式,所以后台php代码要么使用两种不同的报告错误的方式:一种给ajax调用请求使用,一种给普通的页面刷新使
用,要么使用统一的错误报告格式,在报告的时候判断一下这是一个ajax调用请求还是一个普通的页面刷新请求。
在php代码中检测是否ajax调用请求的方法是:
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// this is an ajax request
}
这个方法来自于google搜索,据说只适用于jQuery发出的ajax请求。 ......
比如要给用户报告一个错误,用下面的方法:
使用set_error_handler设置自己的错误处理函数,在报错的地方使用trigger_error,在自定义的错误处理函数中给用户显示一个出错信息页面。
但
是如果调用trigger_error的这个页面是被一次ajax请求触发的,那么ajax返回后将得到一大堆用于显示错误的html代码。而一般
ajax调用都会约定自己的错误信息格式,所以后台php代码要么使用两种不同的报告错误的方式:一种给ajax调用请求使用,一种给普通的页面刷新使
用,要么使用统一的错误报告格式,在报告的时候判断一下这是一个ajax调用请求还是一个普通的页面刷新请求。
在php代码中检测是否ajax调用请求的方法是:
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// this is an ajax request
}
这个方法来自于google搜索,据说只适用于jQuery发出的ajax请求。 ......
以前把php当作一个纯粹的系统编程脚本,从3月份开始第一次使用php写web网站,一点经验在这里总结一下。
一:打开错误显示和错误日志。在php.ini中把dispaly_errors设置为On,或者在脚本开头用ini_set('display_errors', 'On')。
二:
调试工具必备。需要两种调试工具:第一种是调试php脚本的,就像C调试器那样可以在脚本中设置断点,单步执行,运行时查看变量值、修改变量值等,我用的
是xdebug +
vim;第二种是调试HTTP的,当页面打开后一片空白,连个错误信息都没有,或者有些ajax调用的地方出现程序错误,这个时候很需要一个工具来查看实
际的HTTP通信过程,我用的是firefox的插件httpfox。
三:自定义错误处理和异常处理程序。错误处理和异常处理这两个是极
好用的东东,我一般用错误处理来向终端用户报告错误,用异常来记录应用程序运行时错误,比如数据库连接错误等。这两类错误我自己也时常分不清楚,我使用它
们的时候基于这个想法:当程序运行出错时,向用户报告的错误信息一定要友好且隐藏数据库和后台代码细节,这个时候就用trigger_error引发自定
义的错误处理程序来报告错误;同时程序员要能够在事后知道程序为什么会出错,这需要记录错误发生处的调用 ......