当前位置: 编程技术>php
本页文章导读:
▪一个SQL管理员的web接口
<? /************************************************************************************* * SQLAdmin v2.0 - An SQL Administration User Interface for the Web * *.........
▪挑战最棒的留言本的源码(二)
post.php 文件 <?php require('config.php'); ?> <?php $nikename=$arr_request['nikename']; if (strlen($nikename)==0) { echo "<center>"; echo "<h2><font color=red>错误信息!</font></h2>";.........
▪如何实现给定日期的若干天以后的日期
这几天突然有很多的人问这样的问题,就是如何在PHP中实现在VB中的DateAdd的函数,呵呵!这个可是问个正着。本来这个问题是 豆腐 去 华为 应聘的时候的一个考试题,不过当时是用C++实现的.........
[1]一个SQL管理员的web接口
来源: 互联网 发布时间: 2013-11-30
<?
/*************************************************************************************
* SQLAdmin v2.0 - An SQL Administration User Interface for the Web *
* Copyright (C) 1997-98 Alessandro Vernet <avernet@scdi.org> *
*************************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, *
* Boston, MA 02111-1307, USA. *
*************************************************************************************/
/* TODO:
* - Add sort order.
* - Add simple view.
* - Add some documentation.
*/
/* LIMITATIONS:
* - Works only with mSQL.
*/
/* HISTORY:
* - 97-11-05 (avernet) Corrected a bug with quote.
* - 98-01-01 (avernet) Added a sortColumn parameter to
* administrationTable function.
* - 98-03-14 (avernet) Added function addTable to enable users to
* add (but not modify) en entry to the database.
* - 98-05-19 (avernet) Submitted to PX.
* - 98-10-11 (avernet) Now SQLAdmin works with PHP3. The PHP2 version
* will not be mainteained anymore.
* - 98-10-11 (avernet) SQLAdmin is now distributed under the LGPL
* instead of MPL.
*/
function escapeforhtml ($string)
{
$result = $string;
//$result = ereg_replace ("\"", """, $result);
$result = ereg_replace ("<", "<", $result);
$result = ereg_replace (">", ">", $result);
return $result;
}
function displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, $mode)
{
$result = "";
$result .= "<FORM METHOD=\"post\"><TABLE BORDER><TR>" .
"<TD BGCOLOR=\"#CCCCFF\">";
$result .= "<TABLE CELLSPACING=\"0\" CELLPADDING=\"0\">";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$result .= "<TR><TD>" . $fieldNames [$fieldIndex] . "</TD><TD>";
if ($fieldLengths [$fieldIndex] <= 128)
{
$result .= "<INPUT TYPE=\"text\" NAME=\"" .
$fieldNames [$fieldIndex] . "\" VALUE=\"" .
$values [$fieldIndex] . "\" SIZE=\"64\">";
}
else
{
$result .= "<TEXTAREA NAME=\"" .
$fieldNames [$fieldIndex] . "\"" .
" COLS=\"64\" ROWS=\"10\" WRAP=\"virtual\">" .
escapeforhtml ($values [$fieldIndex]) . "</TEXTAREA>";
}
$result .= "<INPUT TYPE=\"hidden\" NAME=\"old-" .
$fieldNames [$fieldIndex] .
"\" VALUE=\"" . escapeforhtml ($values [$fieldIndex]) . "\">" .
"</TD></TR>";
$fieldIndex++;
}
$result .= "<TR><TD ALIGN=\"center\" COLSPAN=\"2\">";
if ($mode == "modify")
{
$result .= "<INPUT TYPE=\"submit\" NAME=\"remove\" VALUE=\"Remove\">";
$result .= "<INPUT TYPE=\"submit\" NAME=\"update\" VALUE=\"Update\">";
}
else
{ $result .= "<INPUT TYPE=\"submit\" NAME=\"add\" VALUE=\"Add\">"; }
$result .= "</TABLE></TD></TR></TABLE></FORM>";
return $result;
}
function fieldFromType ($text, $type)
{
if ($type == "int" || $type == "uint" || $type == "real")
{ $result = $text; }
else
{ $result = "'" . AddSlashes ($text) . "'"; }
return $result;
}
function executeMsql ($database, $command)
{
/*echo "<TT>" . $command . "</TT><HR>";*/
msql ($database, $command);
}
function handleRemove ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
global $remove;
if ($remove != "")
{
$command = "DELETE FROM " . $table . " WHERE ";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = "old-" . $fieldNames [$fieldIndex];
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; }
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleUpdate ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
global $update;
if ($update != "")
{
$command = "UPDATE " . $table . " SET ";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = $fieldNames [$fieldIndex];
global $$fieldName;
$command .= $fieldName . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= " WHERE ";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = "old-" . $fieldNames [$fieldIndex];
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; }
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleAdd ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
global $add;
if ($add != "")
{
$command = "INSERT INTO " . $table . " (";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$command .= $fieldNames [$fieldIndex];
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= ") VALUES (";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = $fieldNames [$fieldIndex];
global $$fieldName;
$command .= fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= ")";
executeMsql ($database, $command);
}
}
function displayRemoveUpdate ($database, $table, $sortColumn,
$fieldsNumber, $fieldNames, $fieldLengths)
{
$result = "";
if ($sortColumn != "")
{ $sortColumn = " ORDER BY " . $sortColumn; }
$msqlresult = msql ($database, "SELECT * FROM " . $table . $sortColumn);
$tuplesNumber = msql_numrows ($msqlresult);
$tupleIndex = 0;
while ($tupleIndex < $tuplesNumber)
{
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$values [$fieldIndex] = msql_result ($msqlresult, $tupleIndex,
$fieldNames [$fieldIndex]);
$fieldIndex++;
}
$result .= displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "modify");
$tupleIndex++;
}
return $result;
}
function displayAdd ($fieldsNumber, $fieldNames, $fieldLengths)
{
$result = "";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$values [$fieldIndex] = "";
$fieldIndex++;
}
$result .= displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "add");
msql_close ();
return $result;
}
function administrationTable ($database, $table, $sortColumn)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table);
$fieldsNumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldNames [$fieldIndex] = msql_fieldname ($msqlresult, $fieldIndex);
$fieldLengths [$fieldIndex] = msql_fieldlen ($msqlresult, $fieldIndex);
$fieldTypes [$fieldIndex] = msql_fieldtype ($msqlresult, $fieldIndex);
$fieldIndex++;
}
handleRemove ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleUpdate ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleAdd ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
$result .= displayRemoveUpdate ($database, $table, $sortColumn, $fieldsNumber, $fieldNames,
$fieldLengths);
$result .= displayAdd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}
function addTable ($database, $table)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table);
$fieldsNumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldNames [$fieldIndex] = msql_fieldname ($msqlresult, $fieldIndex);
$fieldLengths [$fieldIndex] = msql_fieldlen ($msqlresult, $fieldIndex);
$fieldTypes [$fieldIndex] = msql_fieldtype ($msqlresult, $fieldIndex);
$fieldIndex++;
}
handleAdd ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
$result .= displayAdd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}
?>
/*************************************************************************************
* SQLAdmin v2.0 - An SQL Administration User Interface for the Web *
* Copyright (C) 1997-98 Alessandro Vernet <avernet@scdi.org> *
*************************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, *
* Boston, MA 02111-1307, USA. *
*************************************************************************************/
/* TODO:
* - Add sort order.
* - Add simple view.
* - Add some documentation.
*/
/* LIMITATIONS:
* - Works only with mSQL.
*/
/* HISTORY:
* - 97-11-05 (avernet) Corrected a bug with quote.
* - 98-01-01 (avernet) Added a sortColumn parameter to
* administrationTable function.
* - 98-03-14 (avernet) Added function addTable to enable users to
* add (but not modify) en entry to the database.
* - 98-05-19 (avernet) Submitted to PX.
* - 98-10-11 (avernet) Now SQLAdmin works with PHP3. The PHP2 version
* will not be mainteained anymore.
* - 98-10-11 (avernet) SQLAdmin is now distributed under the LGPL
* instead of MPL.
*/
function escapeforhtml ($string)
{
$result = $string;
//$result = ereg_replace ("\"", """, $result);
$result = ereg_replace ("<", "<", $result);
$result = ereg_replace (">", ">", $result);
return $result;
}
function displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, $mode)
{
$result = "";
$result .= "<FORM METHOD=\"post\"><TABLE BORDER><TR>" .
"<TD BGCOLOR=\"#CCCCFF\">";
$result .= "<TABLE CELLSPACING=\"0\" CELLPADDING=\"0\">";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$result .= "<TR><TD>" . $fieldNames [$fieldIndex] . "</TD><TD>";
if ($fieldLengths [$fieldIndex] <= 128)
{
$result .= "<INPUT TYPE=\"text\" NAME=\"" .
$fieldNames [$fieldIndex] . "\" VALUE=\"" .
$values [$fieldIndex] . "\" SIZE=\"64\">";
}
else
{
$result .= "<TEXTAREA NAME=\"" .
$fieldNames [$fieldIndex] . "\"" .
" COLS=\"64\" ROWS=\"10\" WRAP=\"virtual\">" .
escapeforhtml ($values [$fieldIndex]) . "</TEXTAREA>";
}
$result .= "<INPUT TYPE=\"hidden\" NAME=\"old-" .
$fieldNames [$fieldIndex] .
"\" VALUE=\"" . escapeforhtml ($values [$fieldIndex]) . "\">" .
"</TD></TR>";
$fieldIndex++;
}
$result .= "<TR><TD ALIGN=\"center\" COLSPAN=\"2\">";
if ($mode == "modify")
{
$result .= "<INPUT TYPE=\"submit\" NAME=\"remove\" VALUE=\"Remove\">";
$result .= "<INPUT TYPE=\"submit\" NAME=\"update\" VALUE=\"Update\">";
}
else
{ $result .= "<INPUT TYPE=\"submit\" NAME=\"add\" VALUE=\"Add\">"; }
$result .= "</TABLE></TD></TR></TABLE></FORM>";
return $result;
}
function fieldFromType ($text, $type)
{
if ($type == "int" || $type == "uint" || $type == "real")
{ $result = $text; }
else
{ $result = "'" . AddSlashes ($text) . "'"; }
return $result;
}
function executeMsql ($database, $command)
{
/*echo "<TT>" . $command . "</TT><HR>";*/
msql ($database, $command);
}
function handleRemove ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
global $remove;
if ($remove != "")
{
$command = "DELETE FROM " . $table . " WHERE ";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = "old-" . $fieldNames [$fieldIndex];
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; }
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleUpdate ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
global $update;
if ($update != "")
{
$command = "UPDATE " . $table . " SET ";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = $fieldNames [$fieldIndex];
global $$fieldName;
$command .= $fieldName . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= " WHERE ";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = "old-" . $fieldNames [$fieldIndex];
global $$fieldName;
$command .= $fieldNames [$fieldIndex] . "=" .
fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= " AND "; }
$fieldIndex++;
}
executeMsql ($database, $command);
}
}
function handleAdd ($database, $table, $fieldsNumber,
$fieldNames, $fieldLengths, $fieldTypes)
{
global $add;
if ($add != "")
{
$command = "INSERT INTO " . $table . " (";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$command .= $fieldNames [$fieldIndex];
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= ") VALUES (";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldName = $fieldNames [$fieldIndex];
global $$fieldName;
$command .= fieldFromType ($$fieldName, $fieldTypes [$fieldIndex]);
if ($fieldIndex != $fieldsNumber - 1)
{ $command .= ", "; }
$fieldIndex++;
}
$command .= ")";
executeMsql ($database, $command);
}
}
function displayRemoveUpdate ($database, $table, $sortColumn,
$fieldsNumber, $fieldNames, $fieldLengths)
{
$result = "";
if ($sortColumn != "")
{ $sortColumn = " ORDER BY " . $sortColumn; }
$msqlresult = msql ($database, "SELECT * FROM " . $table . $sortColumn);
$tuplesNumber = msql_numrows ($msqlresult);
$tupleIndex = 0;
while ($tupleIndex < $tuplesNumber)
{
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$values [$fieldIndex] = msql_result ($msqlresult, $tupleIndex,
$fieldNames [$fieldIndex]);
$fieldIndex++;
}
$result .= displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "modify");
$tupleIndex++;
}
return $result;
}
function displayAdd ($fieldsNumber, $fieldNames, $fieldLengths)
{
$result = "";
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$values [$fieldIndex] = "";
$fieldIndex++;
}
$result .= displayTuple ($fieldsNumber, $fieldNames,
$fieldLengths, $values, "add");
msql_close ();
return $result;
}
function administrationTable ($database, $table, $sortColumn)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table);
$fieldsNumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldNames [$fieldIndex] = msql_fieldname ($msqlresult, $fieldIndex);
$fieldLengths [$fieldIndex] = msql_fieldlen ($msqlresult, $fieldIndex);
$fieldTypes [$fieldIndex] = msql_fieldtype ($msqlresult, $fieldIndex);
$fieldIndex++;
}
handleRemove ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleUpdate ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
handleAdd ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
$result .= displayRemoveUpdate ($database, $table, $sortColumn, $fieldsNumber, $fieldNames,
$fieldLengths);
$result .= displayAdd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}
function addTable ($database, $table)
{
$result = "";
msql_connect ( "localhost");
$msqlresult = msql ($database, "SELECT * FROM " . $table);
$fieldsNumber = msql_numfields ($msqlresult);
$msqlresult = msql_listfields ($database, $table);
$fieldIndex = 0;
while ($fieldIndex < $fieldsNumber)
{
$fieldNames [$fieldIndex] = msql_fieldname ($msqlresult, $fieldIndex);
$fieldLengths [$fieldIndex] = msql_fieldlen ($msqlresult, $fieldIndex);
$fieldTypes [$fieldIndex] = msql_fieldtype ($msqlresult, $fieldIndex);
$fieldIndex++;
}
handleAdd ($database, $table, $fieldsNumber, $fieldNames, $fieldLengths, $fieldTypes);
$result .= displayAdd ($fieldsNumber, $fieldNames, $fieldLengths);
return $result;
}
?>
[2]挑战最棒的留言本的源码(二)
来源: 互联网 发布时间: 2013-11-30
post.php 文件
<?php
require('config.php');
?>
<?php
$nikename=$arr_request['nikename'];
if (strlen($nikename)==0)
{
echo "<center>";
echo "<h2><font color=red>错误信息!</font></h2>";
echo "对不起,<font color=red>呢称</font>必须填写!!! 请重填!<br>";
echo "<hr></hr>";
echo "免费留言本由<a href=http://little.oso.com.cn>小熊</a>提供技术支持";
echo "</center>";
exit ;
}
$date_now=date('Y/m/d H:i:s');
$ip_address=getenv("REMOTE_ADDR");
$messageold=$arr_request['message'];
//$pattern="/n/";
//$replacement="<br>";
$message=computer_message($messageold,$hang_zifu_number);
$subjectold=$arr_request['subject'];
if (strlen($subjectold)>$hang_zifu_number)
$subject=computer_message($subjectold,$hang_zifu_number);
else
$subject=$subjectold;
$str_sql=" insert into $table_name
(nikename,subject,date_created,ip_address,message,email_address,zhuye_address,oicq)
values
( '$nikename',
'$subject',
'$date_now',
'$ip_address',
'$message',
'".$arr_request['email_address']."',
'".$arr_request['zhuye_address']."',
'".$arr_request['oicq']."'
)";
$result=mysql_db_query($db_name,$str_sql,$id_link);
if (! $result){
affy_error_exit('SQL Insert Execution has failed.');
}
else
{
echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">";
echo "<HTML><HEAD><TITLE>发表文章</TITLE>";
echo "<META content="text/html; charset=gb2312" http-equiv=Content-Type>";
echo "<meta HTTP-EQUIV="REFRESH" CONTENT="2;URL=display.php">";
echo "</head><body topmargin="0"><br>";
echo "<ul>谢谢你发表留言,将自动显示留言内容";
echo " <br>";
echo "<a href=/blog_article/display/.html
请点这里返回.";
echo "</a></ul>";
exit;
}
?>
index.html 文件
<html>
<center>
<title>谢谢你的留言!</title>
<h1><font color=blue>我的留言本</font></h1>
<font color=navy>首先感谢你的留言,你的每一句话我都会仔细阅读!!!</font>
<form action="/blog_article/post.html" method="post">
<table>
<tr>
<td><font color=teal>呢称:</font><font color=red>(不能为空)</font></td><td>
<input type="text" name="nikename" value=""></td>
</tr>
<tr>
<td>OICQ号码:</td><td>
<input type="text" name="oicq" value=""></td>
</tr>
<tr>
<td>e-mail: </td><td>
<input type="text" name="email_address" value="" size="30"></td>
</tr>
<tr>
<td>个人主页:</td><td>
<input type="text" name="zhuye_address" value="http://" size="40"></td>
</tr>
<tr><td>
主题:</td><td>
<input type="text" name="subject" size="40" ></td>
</tr>
<tr><td>
内容:</td><td> </td>
</tr>
<tr><td colspan="2">
<textarea name="message" cols="60" rows="8"></textarea></td>
</tr>
<tr>
<td>
<input type="submit" value="完成留言">
</td>
<td>
<input type="reset" value="重新来过">
</td>
</tr>
</table>
</form>
<p>
<a href=/blog_article/display.php>查看留言</a>/index.html
<hr></hr>
免费留言本由<a href="http://little.oso.com.cn" >小熊</a>提供技术支持
</center>
</html>
display.inc文件!!!
<tr bgcolor=>
<td>
<a href=mailto:<?php echo $record->email_address ?> >
<font color="blue" size=4><strong><?php echo $record->nikename ?></strong></font>
</a>
</td>
<td><font color="navy">留言时间:<?php echo $record->date_created ?></font></td>
<td>来自:
<?php
$ip_address=ip_question($record->ip_address);
echo $ip_address;
?>
</td>
</tr>
<tr bgcolor=>
<th colspan=3 align=left>主题:<font color=teal><?php echo $record->subject ?></font></th>
</tr>
<tr><th colspan=3 align=left><font color="#416AAF">
<?php echo $record->message ?></font></th>
</tr>
<?php
if ($record->huifu_biaozi)
{
?>
<tr><th colspan=3 align=left><font color="red"><br><br>版主回复:</font><font color="navy">
<?php echo $record->huifu ?></font></th>
</tr>
<?php
}
?>
<tr>
<th colspan=3 align=left><br>
<a href=mailto:<?php echo $record->email_address ?> >
<img src=/blog_article/image/mail.gif>alt="<?php echo $record->nikename ?>的e-mail地址是:<?php echo $record->email_address ?> "
border="0" width="15" length="15">邮件</a>
<a href=/blog_article/</php.html echo $record->zhuye_address ?>><img src=/blog_article/image/home.gif>alt="<?php echo $record->nikename ?>的主页地址是:<?php echo $record->zhuye_address ?> "
border="0"
width="14" length="14" >主页</a>
<img src=/blog_article/image/oicq.gif border="0" alt="<?php echo $record->nikename?>的OICQ是:
<?php echo $record->oicq ?>"
width="14" length="14" >OICQ</a>
<a href=/blog_article/action/action/delete/amp;key_liuyan/lt;php.html echo $record->key_liuyan ?>><img src=/blog_article/image/del.gif border="0" width="12" length="12" alt="只有版主才有删除的权限哦!">删除</a>
<a href=/blog_article/action/action/huifu/amp;key_liuyan/lt;php.html echo $record->key_liuyan ?> ><img src=/blog_article/image/replay.gif border="0" width="14" length="14" alt="不好意思,现在暂时只有版主才能回复">回复</a>
</th></tr>
<tr>
<td colspan="3"><hr SIZE ="1"></td>
</tr>
<?php
require('config.php');
?>
<?php
$nikename=$arr_request['nikename'];
if (strlen($nikename)==0)
{
echo "<center>";
echo "<h2><font color=red>错误信息!</font></h2>";
echo "对不起,<font color=red>呢称</font>必须填写!!! 请重填!<br>";
echo "<hr></hr>";
echo "免费留言本由<a href=http://little.oso.com.cn>小熊</a>提供技术支持";
echo "</center>";
exit ;
}
$date_now=date('Y/m/d H:i:s');
$ip_address=getenv("REMOTE_ADDR");
$messageold=$arr_request['message'];
//$pattern="/n/";
//$replacement="<br>";
$message=computer_message($messageold,$hang_zifu_number);
$subjectold=$arr_request['subject'];
if (strlen($subjectold)>$hang_zifu_number)
$subject=computer_message($subjectold,$hang_zifu_number);
else
$subject=$subjectold;
$str_sql=" insert into $table_name
(nikename,subject,date_created,ip_address,message,email_address,zhuye_address,oicq)
values
( '$nikename',
'$subject',
'$date_now',
'$ip_address',
'$message',
'".$arr_request['email_address']."',
'".$arr_request['zhuye_address']."',
'".$arr_request['oicq']."'
)";
$result=mysql_db_query($db_name,$str_sql,$id_link);
if (! $result){
affy_error_exit('SQL Insert Execution has failed.');
}
else
{
echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">";
echo "<HTML><HEAD><TITLE>发表文章</TITLE>";
echo "<META content="text/html; charset=gb2312" http-equiv=Content-Type>";
echo "<meta HTTP-EQUIV="REFRESH" CONTENT="2;URL=display.php">";
echo "</head><body topmargin="0"><br>";
echo "<ul>谢谢你发表留言,将自动显示留言内容";
echo " <br>";
echo "<a href=/blog_article/display/.html
请点这里返回.";
echo "</a></ul>";
exit;
}
?>
index.html 文件
<html>
<center>
<title>谢谢你的留言!</title>
<h1><font color=blue>我的留言本</font></h1>
<font color=navy>首先感谢你的留言,你的每一句话我都会仔细阅读!!!</font>
<form action="/blog_article/post.html" method="post">
<table>
<tr>
<td><font color=teal>呢称:</font><font color=red>(不能为空)</font></td><td>
<input type="text" name="nikename" value=""></td>
</tr>
<tr>
<td>OICQ号码:</td><td>
<input type="text" name="oicq" value=""></td>
</tr>
<tr>
<td>e-mail: </td><td>
<input type="text" name="email_address" value="" size="30"></td>
</tr>
<tr>
<td>个人主页:</td><td>
<input type="text" name="zhuye_address" value="http://" size="40"></td>
</tr>
<tr><td>
主题:</td><td>
<input type="text" name="subject" size="40" ></td>
</tr>
<tr><td>
内容:</td><td> </td>
</tr>
<tr><td colspan="2">
<textarea name="message" cols="60" rows="8"></textarea></td>
</tr>
<tr>
<td>
<input type="submit" value="完成留言">
</td>
<td>
<input type="reset" value="重新来过">
</td>
</tr>
</table>
</form>
<p>
<a href=/blog_article/display.php>查看留言</a>/index.html
<hr></hr>
免费留言本由<a href="http://little.oso.com.cn" >小熊</a>提供技术支持
</center>
</html>
display.inc文件!!!
<tr bgcolor=>
<td>
<a href=mailto:<?php echo $record->email_address ?> >
<font color="blue" size=4><strong><?php echo $record->nikename ?></strong></font>
</a>
</td>
<td><font color="navy">留言时间:<?php echo $record->date_created ?></font></td>
<td>来自:
<?php
$ip_address=ip_question($record->ip_address);
echo $ip_address;
?>
</td>
</tr>
<tr bgcolor=>
<th colspan=3 align=left>主题:<font color=teal><?php echo $record->subject ?></font></th>
</tr>
<tr><th colspan=3 align=left><font color="#416AAF">
<?php echo $record->message ?></font></th>
</tr>
<?php
if ($record->huifu_biaozi)
{
?>
<tr><th colspan=3 align=left><font color="red"><br><br>版主回复:</font><font color="navy">
<?php echo $record->huifu ?></font></th>
</tr>
<?php
}
?>
<tr>
<th colspan=3 align=left><br>
<a href=mailto:<?php echo $record->email_address ?> >
<img src=/blog_article/image/mail.gif>alt="<?php echo $record->nikename ?>的e-mail地址是:<?php echo $record->email_address ?> "
border="0" width="15" length="15">邮件</a>
<a href=/blog_article/</php.html echo $record->zhuye_address ?>><img src=/blog_article/image/home.gif>alt="<?php echo $record->nikename ?>的主页地址是:<?php echo $record->zhuye_address ?> "
border="0"
width="14" length="14" >主页</a>
<img src=/blog_article/image/oicq.gif border="0" alt="<?php echo $record->nikename?>的OICQ是:
<?php echo $record->oicq ?>"
width="14" length="14" >OICQ</a>
<a href=/blog_article/action/action/delete/amp;key_liuyan/lt;php.html echo $record->key_liuyan ?>><img src=/blog_article/image/del.gif border="0" width="12" length="12" alt="只有版主才有删除的权限哦!">删除</a>
<a href=/blog_article/action/action/huifu/amp;key_liuyan/lt;php.html echo $record->key_liuyan ?> ><img src=/blog_article/image/replay.gif border="0" width="14" length="14" alt="不好意思,现在暂时只有版主才能回复">回复</a>
</th></tr>
<tr>
<td colspan="3"><hr SIZE ="1"></td>
</tr>
[3]如何实现给定日期的若干天以后的日期
来源: 互联网 发布时间: 2013-11-30
这几天突然有很多的人问这样的问题,就是如何在PHP中实现在VB中的DateAdd的函数,呵呵!这个可是问个正着。
本来这个问题是 豆腐 去 华为 应聘的时候的一个考试题,不过当时是用C++实现的。没有想到这样的大公司,竟
然用这样的小儿科来考试:),后来我没有去,这两天 应 http://www.chinaspx.com 的 网友--》运气,用PHP重新
写了这个函数。
这个函数是很简单,就是加上给 指定时间加上一天,得到新生成的日期,如果要扩展,也是很简单的。
下面首先来看这个函数,首先要提前讲个函数,判断当前是否是闰年的函数
function CheckRun($year){
if($year%4==0 && ($year%100!=0 || $year%400==0) )
return true;
else
return false;
}
我们要在下面的程序中用到这个函数
function DateAdd($date){
$parts = explode(' ', $date);
$date = $parts[0];
$time = $parts[1];
$ymd = explode('-', $date);
$hms = explode(':', $time);
$year = $ymd[0];
$month = $ymd[1];
$day = $ymd[2];
$hour = $hms[0];
$minute = $hms[1];
$second = $hms[2];
$day=$day+1 ; //废话少说,先把日期加一再说
if($month=='1' || $month=='3' || $month=='5' || $month=='7' || $month=='8' || $month=='10' || $month=='12')
if($day==32)
{
$day='1';
$month++;
}
if($month=='4' || $month=='6' || $month=='9' || $month=='11')
if($day==31)
{
$day='1';
$month++;
}
if($month=='2')
if(CheckRun($year))
{
//闰年 2月有 29 天
if($day==30)
{
$day=1;
$month++;
}
}
else
{
//不是闰年
if($day==29)
{
$day=1;
$month++;
}
}
if($month==13)
{
$month=1;
$year++;
}
return $year . "-" . $month . "-" . $day;
}
好了,下面来测试一下
echo DateAdd("1999-12-31 11:11:11");
echo DateAdd("2000-2-29 11:11:11");
如果要测试增加若干天,只要加个循环就可以了,相信大家都是 高人,这个功能很简单吧:)
本来这个问题是 豆腐 去 华为 应聘的时候的一个考试题,不过当时是用C++实现的。没有想到这样的大公司,竟
然用这样的小儿科来考试:),后来我没有去,这两天 应 http://www.chinaspx.com 的 网友--》运气,用PHP重新
写了这个函数。
这个函数是很简单,就是加上给 指定时间加上一天,得到新生成的日期,如果要扩展,也是很简单的。
下面首先来看这个函数,首先要提前讲个函数,判断当前是否是闰年的函数
function CheckRun($year){
if($year%4==0 && ($year%100!=0 || $year%400==0) )
return true;
else
return false;
}
我们要在下面的程序中用到这个函数
function DateAdd($date){
$parts = explode(' ', $date);
$date = $parts[0];
$time = $parts[1];
$ymd = explode('-', $date);
$hms = explode(':', $time);
$year = $ymd[0];
$month = $ymd[1];
$day = $ymd[2];
$hour = $hms[0];
$minute = $hms[1];
$second = $hms[2];
$day=$day+1 ; //废话少说,先把日期加一再说
if($month=='1' || $month=='3' || $month=='5' || $month=='7' || $month=='8' || $month=='10' || $month=='12')
if($day==32)
{
$day='1';
$month++;
}
if($month=='4' || $month=='6' || $month=='9' || $month=='11')
if($day==31)
{
$day='1';
$month++;
}
if($month=='2')
if(CheckRun($year))
{
//闰年 2月有 29 天
if($day==30)
{
$day=1;
$month++;
}
}
else
{
//不是闰年
if($day==29)
{
$day=1;
$month++;
}
}
if($month==13)
{
$month=1;
$year++;
}
return $year . "-" . $month . "-" . $day;
}
好了,下面来测试一下
echo DateAdd("1999-12-31 11:11:11");
echo DateAdd("2000-2-29 11:11:11");
如果要测试增加若干天,只要加个循环就可以了,相信大家都是 高人,这个功能很简单吧:)
最新技术文章: