这是一款老外写的mysql php接受数据过来然后进行数据保存在mysql_real_escape_string(nl2br(strip_tags($_POST[\'comment\'])));我觉得写得我们有一点区别吧。
database config
*/
代码如下 |
复制代码 |
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_database = '';
$link = mysql_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection');
mysql_select_db($db_database,$link);
mysql_query("set names utf8");
if(empty($_post['comment'])) die("0");
// if there isn't a comment text, exit
$comment = mysql_real_escape_string(nl2br(strip_tags($_post['comment'])));
$user='demo';
// this would be a nice place to start customizing - the default user
// you can integrate it to any site and show a different username.
$addon='';
if($_post['parent']) $addon=',parent='.(int)$_post['parent'];
mysql_query("insert into wave_comments set usr='".$user."', comment='".$comment."', dt=now()".$addon);
if(mysql_affected_rows($link)==1)
echo mysql_insert_id($link);
// if the insert was successful, echo the newly assigned id
else
echo '0';
?>
|
sql
--
-- table structure for table `wave_comments`
--
create table `wave_comments` (
`id` int(11) not null auto_increment,
`parent` int(11) not null default '0',
`usr` varchar(16) collate utf8_unicode_ci not null default '',
`comment` text collate utf8_unicode_ci not null,
`dt` datetime not null default '0000-00-00 00:00:00',
primary key (`id`),
key `parent` (`parent`,`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci;
--
-- dumping data for table `wave_comments`
--
insert into `wave_comments` values(1, 0, 'tutorialzine', 'this is a demo for a tutorialzine tutorial about creating a google wave-like history slider.<br /><br />rnto get started, just drag the slider above, and this thread will be reverted to a past state.', '2009-10-24 03:58:08');
insert into `wave_comments` values(2, 0, 'curious', 'is html allowed in the comments?', '2009-10-24 03:59:44');
insert into `wave_comments` values(3, 2, 'tutorialzine', 'nope. also the messages in this demo are deleted every hour to prevent spamming.', '2009-10-24 04:00:15');
insert into `wave_comments` values(4, 1, 'tutorialzine', 'in this tutorial we are using <b>php</b>, <b>mysql</b>, <b>jquery</b> and <b>css教程</b>. the slider was created with <b>jquery ui</b>. <a href="http://111cn.net/2009/10/google-wave-history-slider-jquery/" target="_blank">view the tutorial</a>.', '2009-10-24 04:01:34');
insert into `wave_comments` values(5, 2, 'curious', 'thanks! also i noticed that you can click, rather than drag the slider.great!', '2009-10-24 04:11:48');
这里把数据库中的常用的内容保存到一个标准的php格式的文件当中,这样使用起来也方便了很多,下面代码。
$res=mysql教程_query("select k1,k2 from ".table('keywords')." ") ;
$str="<?php rn ";
while($rs=mysql_fetch_array($res))
{
$str .="$keyword['".$rs[0]."']='".$rs[1]."';rn";
}
$str.="?>";
file_put_contents("keyword.php",$str);
echo "导出成功";
//方法二
$f=file_get_contents("w1.txt");
$f=str_replace("rn","<br>",$f);//替换换行符
$arr=explode("<br>",$f);
$str="<?php rn ";
foreach($arr as $t)
{
$rs=explode("|",$t);
//不能包含?等特殊符号
$str .="$keyword['".str_replace("?","",$rs[0])."']='".str_replace("?","",$rs[1])."';rn";
}
$str.="?>";
file_put_contents("keyword.php",$str);
echo "导出成功";
//conn.php文件
$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('连接服务器出错');
mysql_select_db($mysql_db) or die("选择数据库出错");
mysql_query("set names 'gbk'");
function table($t)
{
global $mysql_table_prefix;
return $mysql_table_prefix.$t;
}
?>
本文章是利用了js php ajax css实现的一款可刷新的js 树形菜单,如果你正在找这类型的类型的树形菜单可以进来免费下载。
代码如下 |
复制代码 |
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.111cn.net/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>simpletree drag</title>
<style>
body
{
font: normal 12px arial, tahoma, helvetica, sans-serif;
margin:0;
padding:20px;
}
.simpletree
{
margin:0;
padding:0;
/*
overflow:auto;
width: 250px;
height:350px;
overflow:auto;
border: 1px solid #444444;
*/
}
.simpletree li
{
list-style: none;
margin:0;
padding:0 0 0 34px;
line-height: 14px;
}
.simpletree li span
{
display:inline;
clear: left;
white-space: nowrap;
}
.simpletree ul
{
margin:0;
padding:0;
}
.simpletree .root
{
margin-left:-16px;
background: url(images/root.gif) no-repeat 16px 0 #ffffff;
}
.simpletree .line
{
margin:0 0 0 -16px;
padding:0;
line-height: 3px;
height:3px;
font-size:3px;
background: url(images/line_bg.gif) 0 0 no-repeat transparent;
}
.simpletree .line-last
{
margin:0 0 0 -16px;
padding:0;
line-height: 3px;
height:3px;
font-size:3px;
background: url(images/spacer.gif) 0 0 no-repeat transparent;
}
.simpletree .line-over
{
margin:0 0 0 -16px;
padding:0;
line-height: 3px;
height:3px;
font-size:3px;
background: url(images/line_bg_over.gif) 0 0 no-repeat transparent;
}
.simpletree .line-over-last
{
margin:0 0 0 -16px;
padding:0;
line-height: 3px;
height:3px;
font-size:3px;
background: url(images/line_bg_over_last.gif) 0 0 no-repeat transparent;
}
.simpletree .folder-open
{
margin-left:-16px;
background: url(images/collaps教程able.gif) 0 -2px no-repeat #fff;
}
.simpletree .folder-open-last
{
margin-left:-16px;
background: url(images/collapsable-last.gif) 0 -2px no-repeat #fff;
}
.simpletree .folder-close
{
margin-left:-16px;
background: url(images/expandable.gif) 0 -2px no-repeat #fff;
}
.simpletree .folder-close-last
{
margin-left:-16px;
background: url(images/expandable-last.gif) 0 -2px no-repeat #fff;
}
.simpletree .doc
{
margin-left:-16px;
background: url(images/leaf.gif) 0 -1px no-repeat #fff;
}
.simpletree .doc-last
{
margin-left:-16px;
background: url(images/leaf-last.gif) 0 -1px no-repeat #fff;
}
.simpletree .ajax
{
background: url(images/spinner.gif) no-repeat 0 0 #ffffff;
height: 16px;
display:none;
}
.simpletree .ajax li
{
display:none;
margin:0;
padding:0;
}
.simpletree .trigger
{
display:inline;
margin-left:-32px;
width: 28px;
height: 11px;
cursor:pointer;
}
.simpletree .text
{
cursor: default;
}
.simpletree .active
{
cursor: default;
background-color:#f7be77;
padding:0px 2px;
border: 1px dashed #444;
}
#drag_container
{
background:#ffffffwww.111cn.net;
color:#000;
font: normal 11px arial, tahoma, helvetica, sans-serif;
border: 1px dashed #767676;
}
#drag_container ul
{
list-style: none;
padding:0;
margin:0;
}
#drag_container li
{
list-style: none;
background-color:#ffffff;
line-height:18px;
white-space: nowrap;
padding:1px 1px 0px 16px;
margin:0;
}
#drag_container li span
{
padding:0;
}
#drag_container li.doc, #drag_container li.doc-last
{
background: url(images/leaf.gif) no-repeat -17px 0 #ffffff;
}
#drag_container .folder-close, #drag_container .folder-close-last
{
background: url(images/expandable.gif) no-repeat -17px 0 #ffffff;
}
#drag_container .folder-open, #drag_container .folder-open-last
{
background: url(/http://mb.111cn.net/collapsable.gif) no-repeat -17px 0 #ffffff;
}
.contextmenu
{
display:none;
}
</style>
<script type="text/网页特效" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.simple.tree.js"></script>
<script type="text/javascript">
var simpletreecollection;
$(document).ready(function(){
simpletreecollection = $('.simpletree').simpletree({
autoclose: true,
afterclick:function(node){
//alert("text-"+$('span:first',node).text());
},
afterdblclick:function(node){
//alert("text-"+$('span:first',node).text());
},
aftermove:function(destination, source, pos){
//alert("destination-"+destination.attr('id')+" source-"+source.attr('id')+" pos-"+pos);
},
afterajax:function()
{
//alert('loaded');
},
animate:true
//,doctofolderconvert:true
});
});
</script>
</head>
<body>
<div class="contextmenu" id="mymenu1">
<ul>
<li id="add"><img src="images/folder_add.png" /> add child</li>
<li id="reload"><img src="images/arrow_refresh.png" /> reload</li>
<li id="edit"><img src="images/folder_edit.png" /> edit</li>
<li id="delete"><img src="images/folder_delete.png" /> delete</li>
</ul>
</div>
<div class="contextmenu" id="mymenu2">
<ul>
<li id="edit"><img src="images/page_edit.png" /> edit</li>
<li id="delete"><img src="images/page_delete.png" /> delete</li>
</ul>
</div>
<ul class="simpletree">
<li class="root" id='1'><span>tree root 1</span>
<ul>
<li class="open" id='2'><span>tree node 1</span>
<ul>
<li id='3'><span>tree node 1-1</span>
<ul class="ajax">
<li id='4'>{url:loadtree.php?tree_id=1}</li>
</ul>
</li>
</ul>
</li>
<li id='5'><span>tree node 2</span>
<ul>
<li id='6'><span>tree node 2-1</span>
<ul>
<li id='7'><span>tree node 2-1-1</span></li>
<li id='8'><span>tree node 2-1-2</span></li>
<li id='9'><span>tree node 2-1-3</span></li>
<li id='10'><span>tree node 2-1-4www.aimeige.com.cn</span>
<ul class="ajax">
<li id='11'>{url:loadtree.php?tree_id=1}</li>
</ul>
</li>
</ul>
</li>
<li id='12'><span>tree node 2-2</span>
<ul>
<li id='13'><span>tree node 2-2-1</span></li>
</ul>
</li>
<li id='14'><span>tree node 2-3</span>
<ul>
<li id='15'><span>tree node 2-3-1</span>
<ul>
<li id='16'><span>tree node 2-3-1-1</span></li>
<li id='17'><span>tree node 2-3-1-2</span></li>
<li id='18'><span>tree node 2-3-1-3</span>
<ul>
<li id='19'><span>tree node 2-3-1-3-1</span></li>
</ul>
</li>
<li id='20'><span>tree node 2-3-1-4</span></li>
<li id='21'><span>tree node 2-3-1-5</span></li>
<li id='22'><span>tree node 2-3-1-6</span>
<ul>
<li id='23'><span>tree node 2-3-1-6-1</span></li>
</ul>
</li>
<li id='24'><span>tree node 2-3-1-7</span></li>
<li id='25'><span>tree node 2-3-1-8</span></li>
<li id='26'><span>tree node 2-3-1-9</span>
<ul>
<li id='27'><span>tree node 2-3-1-9-1</span></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</body>
</html>
php文件
<li id='35'><span class="text">tree node ajax 1</span></li>
<li id='36'><span class="text">tree node ajax 2</span></li>
<li id='37'><span class="text">tree node ajax 3</span>
<ul>
<li id='38'><span class="text">tree node ajax 3-1</span>
<ul>
<li id='39'><span class="text">tree node ajax 3-1-1</span></li>
<li id='40'><span class="text">tree node ajax 3-1-2</span></li>
<li id='41'><span class="text">tree node ajax 3-1-3</span></li>
<li id='42'><span class="text">tree node ajax 3-1-4</span></li>
</ul>
</li>
<li id='43'><span class="text">tree node ajax 3-2</span></li>
<li id='44'><span class="text">tree node ajax 3-3</span>
<ul>
<li id='45'><span class="text">tree node ajax 3-3-1</span></li>
<li id='46'><span class="text">tree node ajax 3-3-2</span></li>
<li id='47'><span class="text">tree node ajax 3-3-3</span></li>
</ul>
</li>
<li id='48'><span class="text">tree node ajax 3-4</span></li>
<li id='49'><span class="text">tree node ajax 3-5</span>
<ul>
<li id='50'><span class="text">tree node ajax 3-5-1</span></li>
<li id='51'><span class="text">tree node ajax 3-5-2</span></li>
<li id='52'><span class="text">tree node ajax 3-5-3</span></li>
</ul>
</li>
<li id='53'><span class="text">tree node ajax 3-6</span></li>
</ul>
</li>
<li id='54'><span class="text">tree node ajax 4</span></li>
|
源码下载
http://down.111cn.net/down/code/jquery/2010/1014/21200.html
效果预览
http://g.111cn.net/javascript/code/20101012/tree
本文章收藏了一款简单php文件上传实例哦,这真的是一款超级简单的文件上传功能代码哦,我们利用php $files来获取要上传文件的,类型,名称与临时名称然后用move_uploaded_file把要上传文件保存到服务器指定目录就OK了。
html代码
代码如下 |
复制代码 |
<input type= "file " id= "userfile " name= "userfile ">
<input type= "submit " name= "upload " value= "上传 "> |
处理上传php代码
代码如下 |
复制代码 |
<?php
function do_upload($upload_dir,$upload_url)
{
$temp_name = $_files[ 'userfile '][ 'tmp_name '];
$file_name = $_files[ 'userfile '][ 'name '];
$file_name = str_replace( "\ ", " ",$file_name);
$file_name = str_replace( " ' ", " ",$file_name);
$file_path = $upload_dir.$file_name;
$thistime=explode( "- ",date( "y-m-d-h-i-s "));
$thistime=mktime();
$filename=$thistime.substr($file_name,strrpos($file_name, ". "));
//文件名检查
if($file_name = ' ')
{
echo "文件名无效。 ";
exit;
}
if(@move_uploaded_file($_files[ 'userfile '][ 'tmp_name '],$upload_dir.$filename))
{
echo "上传成功。 ";
echo " <meta http-equiv= "refresh " content= "1;url=www.aimeige.com.cn.php "> ";
exit;
}else
{
echo "上传失败。 ";
echo " <meta http-equiv= "refresh " content= "1;url=www.111cn.net.php "> ";
exit;
}
echo "end ";
}
?>
|
代码如下 |
复制代码 |
$upload_dir ='down.111cn.net'; $upload_url='www.111cn.net'; |
代码如下 |
复制代码 |
do_upload($upload_dir,$upload_url) ;
|
关于缓存技术不只在php有,很多系统都有,这是为了减轻服务吕压力与数据库压力来做的,本文章从php缓存技术入门到利用缓存实例来告诉你如何应用php来实例文件缓存描述。
先看这个缓存类
<?php
代码如下 |
复制代码 |
class cache{
/*
class name: cache
description: control to cache data,$cache_out_time is a array to save cache date time out.
version: 1.0
author: 老农 cjjer
last modify:2006-2-26
author url: http://www.111cn.net*/
private $cache_dir;
private $expiretime=180;//缓存的时间是 60 秒
function __construct($cache_dirname){
if(!@is_dir($cache_dirname)){
if(!@mkdir($cache_dirname,0777)){
$this->warn('缓存文件不存在而且不能创建,需要手动创建.');
return false;
}
}
$this->cache_dir = $cache_dirname;
}
function __destruct(){
echo 'cache class bye.';
}
function get_url() {
if (!isset($_server['request_uri'])) {
$url = $_server['request_uri'];
}else{
$url = $_server['script_name'];
$url .= (!empty($_server['query_string'])) ? '?' . $_server['query_string'] : '';
}
return $url;
}
function warn($errorstring){
echo "<b><font color='red'>发生错误:<pre>".$errorstring."</pre></font></b>";
}
function cache_page($pageurl,$pagedata){
if(!$fso=fopen($pageurl,'w')){
$this->warns('无法打开缓存文件.');//trigger_error
return false;
}
if(!flock($fso,lock_ex)){//lock_nb,排它型锁定
$this->warns('无法锁定缓存文件.');//trigger_error
return false;
}
if(!fwrite($fso,$pagedata)){//写入字节流,serialize写入其他格式
$this->warns('无法写入缓存文件.');//trigger_error
return false;
}
flock($fso,lock_un);//释放锁定
fclose($fso);
return true;
}
|