写出你的经典代码?给代码有分? <?php echo ('Hello World!');?>不可能有比这个经典的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请看这个论坛的FAQ!!你看完后就绝对是半个高手了 我想要的是经典PHP代码.像JAVASCRIPT就不用了.另外:有官方资源网站吗?(像MSDN这样的)有比较好的PHP学习网站吗? www.google.comwww.phpx.com/happy/www.phpe.net 经典代码?<?phpinclude_once 'exception/exception.class.php';include_once 'phplib_template.class.php';include_once 'PEAR/DB.php';include_once 'config.cfg.php';include_once 'page.class.php';class manage{ protected $tpl; protected $DB; /** * Construct function,to Init templateClass and Database connect */ public function __construct($DSN) { try { $this->cacheTPL = new cacheTemplate("template/admin_template", "remove"); $this->tpl = new Template("template/admin_template", "remove"); } catch (templateException $tplex) { print $tplex->getMessage(); exit; } $this->DB = DB::connect($DSN); if (DB::isError($this->DB)) { print $this->DB->getMessage(); exit; } return true; } }class categoryManage extends manage{ /** * Construct function,to Init templateClass and Database connect */ public function __construct($DSN) { parent::__construct($DSN); } /** * Control method >> show the category add page */ public function showAddForm($vars = array(), $tplFile = "category_showAddForm.html") { if ($this->cacheTPL->isCached("category_showaddform")) { $this->cacheTPL->printCache("category_showaddform"); exit; } try { $this->cacheTPL->setFile("showAddForm", $tplFile, "category_showaddform"); if (count($vars) != 0) { $this->cacheTPL->setVar($vars); } $this->cacheTPL->setBlock("showAddForm", "pcSelectList", "pcSelectLists"); $queryRes = $this->DB->query("select `name`,`ID` from contentcategory"); if (DB::isError($queryRes)) { echo "<p>" .$queryRes->getMessage()."</p><p>数据库错误</p>"; exit; } while($res = $queryRes->fetchRow()) { $this->cacheTPL->setVar("categoryName", $res[0]); $this->cacheTPL->setVar("categoryID", $res[1]); $this->cacheTPL->parse("pcSelectLists", "pcSelectList", true); } $this->cacheTPL->setBlock("showAddForm", "tplSelectList", "tplSelectLists"); $queryRes = $this->DB->query("select `name`,`ID` from `template`"); if (DB::isError($queryRes)) { echo "<p>" .$queryRes->getMessage()."</p><p>数据库错误</p>"; exit; } while($res = $queryRes->fetchRow()) { $this->cacheTPL->setVar("templateName", $res[0]); $this->cacheTPL->setVar("templateID", $res[1]); $this->cacheTPL->parse("tplSelectLists", "tplSelectList", true); } $this->cacheTPL->pparse("showAddForms", "showAddForm"); } catch (templateException $tplex) { print $tplex->getMessage(); exit; } return true; } public function showListMain($vars = array(), $tplFile = "category_showListMain.html") { if ($this->cacheTPL->isCached("category_showlistmain")) { $this->cacheTPL->printCache("category_showlistmain"); exit; } try { $this->cacheTPL->setFile("showListMain", $tplFile, "category_showlistmain"); if (count($vars) != 0) { $this->cacheTPL->setVar($vars); } $this->cacheTPL->setBlock("showListMain", "list", "lists"); $queryRes = $this->DB->query("select * from `contentCategory`"); while ($res = $queryRes->fetchRow()) { $this->cacheTPL->setVar("name", $res[0]); $this->cacheTPL->setVar("type", $res[1]); if ($res[3] == 0) { $this->cacheTPL->setVar("parent", '无'); } $this->cacheTPL->setVar("tplname", $res[6]); $this->cacheTPL->setVar("caption", $res[4]); $this->cacheTPL->setVar("description", $res[5]); $this->cacheTPL->setVar("id", $res[7]); $this->cacheTPL->setVar("display", $res[2] == 1? '是': '否'); $this->cacheTPL->setVar("", $res[]); $this->cacheTPL->parse("lists", "list", true); } $this->cacheTPL->pparse("showListMains", "showListMain"); } catch (templateException $tplex) { print $tplex->getMessage(); exit; } catch (DBException $DBex) { print $DBex->getMessage(); exit; } return true; } public function addNewCategory() { if (page::safePost('type') == "") { $type = "artical"; } else { $type = page::safePost('type'); } if (page::safePost('topCategory') == 1) { $parentID = 0; $topCategory = 1; } else { $topCategory = 0; } if (page::safePost('parentCategory') == 'null') { $topCategory = 1; $parentID = 0; } else { $parentID = page::safePost('parentCategory'); } if (page::safePost('className') == "") { die("<script>alert('请输入分类名称');history.back(1);</script>"); } else { $className = page::safePost('className'); } if (page::safePost('classIntroduce') == "") { $classIntroduce = ""; } else { $classIntroduce = page::safePost('classIntroduce'); } if (page::safePost('tplSelect') == "") { die("<script>alert('请选择一个模板');history.back(1);</script>"); } else { $tplid = page::safePost('tplSelect'); } $showIntroduceOnPage = (int)page::safePost('showIntroduceOnPage'); try{ $this->DB->query("select * from `contentCategory` where `name`='$className' and `type`='$type' and `parentID` = '$parentID'"); if ($this->DB->affectedRows() != 0) { die("<script>alert('已经存在一个同名、同父类的分类');history.back(1);</script>"); } $this->DB->query("insert into `contentCategory` values('$className','$type', '$showIntroduceOnPage', '$parentID', '$classIntroduce', '', '$tplid', '')"); echo "<script>alert('类别".$className."添加成功');window.href='manage.php?class=categoryManage&method=showListMain';</script>"; } catch(DBException $DBex) { print $DBex->getMessage(); exit; } $this->cacheTPL->refresh('showlistmain'); return true; } /* public function delete() { if (page::safeGet('id') == "" or strlen(page::safeGet('id')) > 2) { $parmeterE = new parmeterException("参数ID非法,请不要手动指定ID", 40000); die(@header("location:error.php?e=".$parmeterE->getCode())); } if (page::safeGet('step') != 2) { try { $this->tpl->setFile("saveMethod", "category_delete_selectsavemethod.html"); $queryRes = $this->DB->query("select * from `contentCategory` where id='".page::safeGet('id')."'"); } catch (DBException $DBe) { print $DBe->getMessage(); exit; } catch (templateException $tple) { print $tple->getMessage(); exit; } } }*/}class contentManage extends manage{ public function __construct($DSN) { parent::__construct($DSN); } public function showAddCategory($vars = array(), $tplFile = "content") { if ($this->cacheTPL->isCached("content_showaddcategory")) { $this->cacheTPL->printCache("content_showaddcategory"); exit; } $this->cacheTemplate->setFile("content_showAddCategory", $tplFile, "content_showaddcategory"); $this->cacheTemplate->setVar($vars); } public function showAddForm($vars = array(), $tplFile = "content") { if ($this->cacheTPL->isCached("content_showaddform")) { $this->cacheTPL->printCache("content_showaddform"); exit; } $this->cacheTemplate->setFile("showAddForm", $tplFile, "content_showaddform"); $this->cacheTemplate->setVar($vars); }}?>调用<?phpinclude_once 'inc/global_session_check.php';include_once 'inc/manage.class.php';include_once 'inc/phplib_template.class.php';if ($_GET['class'] == "" || $_GET['method'] == "") { } else { $classInstence = new $_GET['class']($DSN); $classInstence->$_GET['method']($vars);}?> config.cfg.php<?php$DBhost = "localhost";$DBuser = "root";$DBpass = "";$DBbase = "fsyd_homepage";$DSN = "mysql://".$DBuser.":".$DBpass."@".$DBhost."/".$DBbase;$vars = array();$programDir = dirname($_SERVER['PHP_SELF']);$vars['programDir'] = substr($programDir, 1, strlen($programDir));$vars['systemName'] = "";?> page.class.php<?php/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=er: */// +----------------------------------------------------------------------+// | PHP Version 5 |// +----------------------------------------------------------------------+// | Copyright (c) [email protected](风随影动) |// +----------------------------------------------------------------------+// +----------------------------------------------------------------------+// | Author: 风随影动<[email protected]> |// | |// +----------------------------------------------------------------------+//// $Id: page.class.php,v 2.0 2005/03/19 22:07:11 Exp $class page { //$_GET private $Gar = array(); //$_POST private $Par = array(); //constractor function public function _construct() { die ("<!-- 这个类不能被实例化 -->程序遇到一个致命异常,已经被关闭"); } //解析替换特殊字符 单引号' 双引号" 反斜线 \ private function parse($values) { if (is_Array($values)) { for (reset($values); $key = key($values); next($values)) { $values[$key] = str_replace("'", "\'", $values[$key]); $values[$key] = str_replace("\\", "", $values[$key]); $values[$key] = str_replace('"', "", $values[$key]); $values[$key] = str_replace('_', "", $values[$key]); } } else { $values = str_replace("'", "\'", $values); $values = str_replace("\\", "\\\\", $values); $values = str_replace('"', "\"", $values); $values = str_replace('_', "", $values); } return $values; } //获取安全的GET参数 public function safeGet($var = false) { if ($var) { $var = $_GET[$var]; return trim(page::parse($var)); } else { return page::parse($_GET); } } //获取安全的POST参数 public function safePost($var = false) { if ($var) { $var = $_POST[$var]; return trim(page::parse($var)); } else { return page::parse($_POST); } } //获取$_SERVER数组 public function Sear($var = false) { if ($var) { return $_SERVER[$var]; } else { return $_SERVER; } } function showErrorPage($msg) { die($msg); }}?> 一本php手册顶半边天另外半边就是自己的经验了 上周末在圖書館轉了一下,翻了幾本PHP的書,發現沒什麽東西看來都是要經驗的 走投无路啦,关于表单的两步提交传递数组的问题 不同服务器之间的数据库操作如何实现? php类图怎么画,谁来举个例子,谢谢? 请教基于Zend Framework开发的开源项目 如何查找当前的网段? 急!请问如何才能捕捉到这个跳转页面? sql的问题 哪位大哥提供两本joomla的好书或者比较好的网站!!!谢谢了. 数组问题 如何做图片上传到mysql里?? 请教一个gb2312转utf8的问题。用两种方式转换后,还是产生乱码~急,请大家帮忙! 急招!深圳某公司招PHP程序员--要求有丰富的企业级开发经验
你看完后就绝对是半个高手了
www.phpx.com/happy/
www.phpe.net
<?php
include_once 'exception/exception.class.php';
include_once 'phplib_template.class.php';
include_once 'PEAR/DB.php';
include_once 'config.cfg.php';
include_once 'page.class.php';
class manage
{
protected $tpl;
protected $DB;
/**
* Construct function,to Init templateClass and Database connect
*/
public function __construct($DSN)
{
try {
$this->cacheTPL = new cacheTemplate("template/admin_template", "remove");
$this->tpl = new Template("template/admin_template", "remove");
} catch (templateException $tplex) {
print $tplex->getMessage();
exit;
}
$this->DB = DB::connect($DSN);
if (DB::isError($this->DB)) {
print $this->DB->getMessage();
exit;
}
return true;
}
}
class categoryManage extends manage
{
/**
* Construct function,to Init templateClass and Database connect
*/
public function __construct($DSN)
{
parent::__construct($DSN);
}
/**
* Control method >> show the category add page
*/
public function showAddForm($vars = array(), $tplFile = "category_showAddForm.html")
{
if ($this->cacheTPL->isCached("category_showaddform")) {
$this->cacheTPL->printCache("category_showaddform");
exit;
}
try {
$this->cacheTPL->setFile("showAddForm", $tplFile, "category_showaddform");
if (count($vars) != 0) {
$this->cacheTPL->setVar($vars);
}
$this->cacheTPL->setBlock("showAddForm", "pcSelectList", "pcSelectLists");
$queryRes = $this->DB->query("select `name`,`ID` from contentcategory");
if (DB::isError($queryRes)) {
echo "<p>" .$queryRes->getMessage()."</p><p>数据库错误</p>";
exit;
}
while($res = $queryRes->fetchRow()) {
$this->cacheTPL->setVar("categoryName", $res[0]);
$this->cacheTPL->setVar("categoryID", $res[1]);
$this->cacheTPL->parse("pcSelectLists", "pcSelectList", true);
}
$this->cacheTPL->setBlock("showAddForm", "tplSelectList", "tplSelectLists");
$queryRes = $this->DB->query("select `name`,`ID` from `template`");
if (DB::isError($queryRes)) {
echo "<p>" .$queryRes->getMessage()."</p><p>数据库错误</p>";
exit;
}
while($res = $queryRes->fetchRow()) {
$this->cacheTPL->setVar("templateName", $res[0]);
$this->cacheTPL->setVar("templateID", $res[1]);
$this->cacheTPL->parse("tplSelectLists", "tplSelectList", true);
}
$this->cacheTPL->pparse("showAddForms", "showAddForm");
} catch (templateException $tplex) {
print $tplex->getMessage();
exit;
}
return true;
}
public function showListMain($vars = array(), $tplFile = "category_showListMain.html")
{
if ($this->cacheTPL->isCached("category_showlistmain")) {
$this->cacheTPL->printCache("category_showlistmain");
exit;
}
try {
$this->cacheTPL->setFile("showListMain", $tplFile, "category_showlistmain");
if (count($vars) != 0) {
$this->cacheTPL->setVar($vars);
}
$this->cacheTPL->setBlock("showListMain", "list", "lists");
$queryRes = $this->DB->query("select * from `contentCategory`");
while ($res = $queryRes->fetchRow()) {
$this->cacheTPL->setVar("name", $res[0]);
$this->cacheTPL->setVar("type", $res[1]);
if ($res[3] == 0) {
$this->cacheTPL->setVar("parent", '无');
}
$this->cacheTPL->setVar("tplname", $res[6]);
$this->cacheTPL->setVar("caption", $res[4]);
$this->cacheTPL->setVar("description", $res[5]);
$this->cacheTPL->setVar("id", $res[7]);
$this->cacheTPL->setVar("display", $res[2] == 1? '是': '否');
$this->cacheTPL->setVar("", $res[]);
$this->cacheTPL->parse("lists", "list", true);
}
$this->cacheTPL->pparse("showListMains", "showListMain");
} catch (templateException $tplex) {
print $tplex->getMessage();
exit;
} catch (DBException $DBex) {
print $DBex->getMessage();
exit;
}
return true;
}
public function addNewCategory()
{
if (page::safePost('type') == "") {
$type = "artical";
} else {
$type = page::safePost('type');
}
if (page::safePost('topCategory') == 1) {
$parentID = 0;
$topCategory = 1;
} else {
$topCategory = 0;
}
if (page::safePost('parentCategory') == 'null') {
$topCategory = 1;
$parentID = 0;
} else {
$parentID = page::safePost('parentCategory');
}
if (page::safePost('className') == "") {
die("<script>alert('请输入分类名称');history.back(1);</script>");
} else {
$className = page::safePost('className');
}
if (page::safePost('classIntroduce') == "") {
$classIntroduce = "";
} else {
$classIntroduce = page::safePost('classIntroduce');
}
if (page::safePost('tplSelect') == "") {
die("<script>alert('请选择一个模板');history.back(1);</script>");
} else {
$tplid = page::safePost('tplSelect');
}
$showIntroduceOnPage = (int)page::safePost('showIntroduceOnPage');
try{
$this->DB->query("select * from `contentCategory` where `name`='$className' and `type`='$type' and `parentID` = '$parentID'");
if ($this->DB->affectedRows() != 0) {
die("<script>alert('已经存在一个同名、同父类的分类');history.back(1);</script>");
}
$this->DB->query("insert into `contentCategory` values('$className','$type', '$showIntroduceOnPage', '$parentID', '$classIntroduce', '', '$tplid', '')");
echo "<script>alert('类别".$className."添加成功');window.href='manage.php?class=categoryManage&method=showListMain';</script>";
} catch(DBException $DBex) {
print $DBex->getMessage();
exit;
}
$this->cacheTPL->refresh('showlistmain');
return true;
}
/*
public function delete()
{
if (page::safeGet('id') == "" or strlen(page::safeGet('id')) > 2) {
$parmeterE = new parmeterException("参数ID非法,请不要手动指定ID", 40000);
die(@header("location:error.php?e=".$parmeterE->getCode()));
}
if (page::safeGet('step') != 2) {
try {
$this->tpl->setFile("saveMethod", "category_delete_selectsavemethod.html");
$queryRes = $this->DB->query("select * from `contentCategory` where id='".page::safeGet('id')."'");
} catch (DBException $DBe) {
print $DBe->getMessage();
exit;
} catch (templateException $tple) {
print $tple->getMessage();
exit;
}
}
}*/
}
class contentManage extends manage
{
public function __construct($DSN)
{
parent::__construct($DSN);
}
public function showAddCategory($vars = array(), $tplFile = "content")
{
if ($this->cacheTPL->isCached("content_showaddcategory")) {
$this->cacheTPL->printCache("content_showaddcategory");
exit;
}
$this->cacheTemplate->setFile("content_showAddCategory", $tplFile, "content_showaddcategory");
$this->cacheTemplate->setVar($vars);
}
public function showAddForm($vars = array(), $tplFile = "content")
{
if ($this->cacheTPL->isCached("content_showaddform")) {
$this->cacheTPL->printCache("content_showaddform");
exit;
}
$this->cacheTemplate->setFile("showAddForm", $tplFile, "content_showaddform");
$this->cacheTemplate->setVar($vars);
}
}
?>调用
<?php
include_once 'inc/global_session_check.php';
include_once 'inc/manage.class.php';
include_once 'inc/phplib_template.class.php';
if ($_GET['class'] == "" || $_GET['method'] == "") {
} else {
$classInstence = new $_GET['class']($DSN);
$classInstence->$_GET['method']($vars);
}
?>
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBbase = "fsyd_homepage";
$DSN = "mysql://".$DBuser.":".$DBpass."@".$DBhost."/".$DBbase;
$vars = array();
$programDir = dirname($_SERVER['PHP_SELF']);
$vars['programDir'] = substr($programDir, 1, strlen($programDir));
$vars['systemName'] = "";
?>
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=er: */
// +----------------------------------------------------------------------+
// | PHP Version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) [email protected](风随影动) |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Author: 风随影动<[email protected]> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: page.class.php,v 2.0 2005/03/19 22:07:11 Exp $
class page {
//$_GET
private $Gar = array();
//$_POST
private $Par = array();
//constractor function
public function _construct() {
die ("<!-- 这个类不能被实例化 -->程序遇到一个致命异常,已经被关闭");
}
//解析替换特殊字符 单引号' 双引号" 反斜线 \
private function parse($values)
{
if (is_Array($values)) {
for (reset($values); $key = key($values); next($values)) {
$values[$key] = str_replace("'", "\'", $values[$key]);
$values[$key] = str_replace("\\", "", $values[$key]);
$values[$key] = str_replace('"', "", $values[$key]);
$values[$key] = str_replace('_', "", $values[$key]);
}
} else {
$values = str_replace("'", "\'", $values);
$values = str_replace("\\", "\\\\", $values);
$values = str_replace('"', "\"", $values);
$values = str_replace('_', "", $values);
}
return $values;
}
//获取安全的GET参数
public function safeGet($var = false)
{
if ($var) {
$var = $_GET[$var];
return trim(page::parse($var));
} else {
return page::parse($_GET);
}
}
//获取安全的POST参数
public function safePost($var = false)
{
if ($var) {
$var = $_POST[$var];
return trim(page::parse($var));
} else {
return page::parse($_POST);
}
}
//获取$_SERVER数组
public function Sear($var = false)
{
if ($var) {
return $_SERVER[$var];
} else {
return $_SERVER;
}
}
function showErrorPage($msg)
{
die($msg);
}
}
?>
另外半边就是自己的经验了