当前位置: 编程技术>php
本页文章导读:
▪用文本文件制作留言板提示(上)
首先是保证文本文件可读写,在文件准备写入之前,我们所要做的是处理好用户留言! 这项工作可以在提交表格前进行,我们将得到的数据各项用特定的符号分开,比如说用&号,值得说.........
▪用函数读出数据表内容放入二维数组
//用函数读出数据表内容放入二维数组 //动态sql语句 //以读出点击次数表为例。 function list_hit($fields,$where,$order,$direction,$limit,$conn) { if ($fields=="") {$fields="hit_id,banner_id,hit_ip,hit_time";} if ($order=="".........
▪给多个地址发邮件的类
<?php //////////////////////////////////////////////////////////// // EmailClass 0.5 // class for sending mail // // Paul Schreiber // php@paulschreiber.com // http://paulschreiber.com/ // // .........
[1]用文本文件制作留言板提示(上)
来源: 互联网 发布时间: 2013-11-30
首先是保证文本文件可读写,在文件准备写入之前,我们所要做的是处理好用户留言!
这项工作可以在提交表格前进行,我们将得到的数据各项用特定的符号分开,比如说用&号,值得说明的是如果提交的数据中如果也包含有特定字符,那我们只好将他转化成其他形式,这一点各位自有办法;
如是我们得到数据形如:
$str=”aaaaa&bbbbb&ccccc&ddddd”;
在将数据写入文件前我们加上
$str=$str.”\r\n”
然后执行:
$fp=fopen("txt/mytxt.txt","a");
fwrite($fp,$txt);
fclose($fp);
这样我们写入的数据位于文件末尾部分
如何让最新的留言出现在留言板的首位?
数据有了以上的处理,就好办了,
$date=file(“txt/mytxt.txt”);
$n=count($date);
for ($I=$n;$I>0;$I--){
$str=explode(“&”,$date[$I])
.
//将得到的$str数组各项输出.
.
}
这样最新插入的留言就保持在首位。
这项工作可以在提交表格前进行,我们将得到的数据各项用特定的符号分开,比如说用&号,值得说明的是如果提交的数据中如果也包含有特定字符,那我们只好将他转化成其他形式,这一点各位自有办法;
如是我们得到数据形如:
$str=”aaaaa&bbbbb&ccccc&ddddd”;
在将数据写入文件前我们加上
$str=$str.”\r\n”
然后执行:
$fp=fopen("txt/mytxt.txt","a");
fwrite($fp,$txt);
fclose($fp);
这样我们写入的数据位于文件末尾部分
如何让最新的留言出现在留言板的首位?
数据有了以上的处理,就好办了,
$date=file(“txt/mytxt.txt”);
$n=count($date);
for ($I=$n;$I>0;$I--){
$str=explode(“&”,$date[$I])
.
//将得到的$str数组各项输出.
.
}
这样最新插入的留言就保持在首位。
[2]用函数读出数据表内容放入二维数组
来源: 互联网 发布时间: 2013-11-30
//用函数读出数据表内容放入二维数组
//动态sql语句
//以读出点击次数表为例。
function list_hit($fields,$where,$order,$direction,$limit,$conn)
{
if ($fields=="") {$fields="hit_id,banner_id,hit_ip,hit_time";}
if ($order=="") {$direction="";}
$sql="select $fields from hit $where $order $direction $limit";
//echo $sql;
$res=mysql_query($sql,$conn);
$i=0;
$list_hit[$i]["rows"]=mysql_num_rows($res);
$i++;
while($rs=mysql_fetch_array($res))
{
$list_hit[$i]["hit_id"]=$rs["hit_id"];
$list_hit[$i]["banner_id"]=$rs["banner_id"];
$list_hit[$i]["hit_ip"]=$rs["hit_ip"];
$list_hit[$i]["hit_time"]=$rs["hit_time"];
$i++;
}
return $list_hit;
}
//动态sql语句
//以读出点击次数表为例。
function list_hit($fields,$where,$order,$direction,$limit,$conn)
{
if ($fields=="") {$fields="hit_id,banner_id,hit_ip,hit_time";}
if ($order=="") {$direction="";}
$sql="select $fields from hit $where $order $direction $limit";
//echo $sql;
$res=mysql_query($sql,$conn);
$i=0;
$list_hit[$i]["rows"]=mysql_num_rows($res);
$i++;
while($rs=mysql_fetch_array($res))
{
$list_hit[$i]["hit_id"]=$rs["hit_id"];
$list_hit[$i]["banner_id"]=$rs["banner_id"];
$list_hit[$i]["hit_ip"]=$rs["hit_ip"];
$list_hit[$i]["hit_time"]=$rs["hit_time"];
$i++;
}
return $list_hit;
}
[3]给多个地址发邮件的类
来源: 互联网 发布时间: 2013-11-30
<?php
////////////////////////////////////////////////////////////
// EmailClass 0.5
// class for sending mail
//
// Paul Schreiber
// php@paulschreiber.com
// http://paulschreiber.com/
//
// parameters
// ----------
// - subject, message, senderName, senderEmail and toList are required
// - ccList, bccList and replyTo are optional
// - toList, ccList and bccList can be strings or arrays of strings
// (those strings should be valid email addresses
//
// example
// -------
// $m = new email ( "hello there", // subject
// "how are you?", // message body
// "paul", // sender's name
// "foo@foobar.com", // sender's email
// array("paul@foobar.com", "foo@bar.com"), // To: recipients
// "paul@whereever.com" // Cc: recipient
// );
//
// print "mail sent, result was" . $m->send();
//
//
//
if ( ! defined( 'MAIL_CLASS_DEFINED' ) ) {
define('MAIL_CLASS_DEFINED', 1 );
class email {
// the constructor!
function email ( $subject, $message, $senderName, $senderEmail, $toList, $ccList=0, $bccList=0, $replyTo=0) {
$this->sender = $senderName . " <$senderEmail>";
$this->replyTo = $replyTo;
$this->subject = $subject;
$this->message = $message;
// set the To: recipient(s)
if ( is_array($toList) ) {
$this->to = join( $toList, "," );
} else {
$this->to = $toList;
}
// set the Cc: recipient(s)
if ( is_array($ccList) && sizeof($ccList) ) {
$this->cc = join( $ccList, "," );
} elseif ( $ccList ) {
$this->cc = $ccList;
}
// set the Bcc: recipient(s)
if ( is_array($bccList) && sizeof($bccList) ) {
$this->bcc = join( $bccList, "," );
} elseif ( $bccList ) {
$this->bcc = $bccList;
}
}
// send the message; this is actually just a wrapper for
// PHP's mail() function; heck, it's PHP's mail function done right :-)
// you could override this method to:
// (a) use sendmail directly
// (b) do SMTP with sockets
function send () {
// create the headers needed by PHP's mail() function
// sender
$this->headers = "From: " . $this->sender . "\n";
// reply-to address
if ( $this->replyTo ) {
$this->headers .= "Reply-To: " . $this->replyTo . "\n";
}
// Cc: recipient(s)
if ( $this->cc ) {
$this->headers .= "Cc: " . $this->cc . "\n";
}
// Bcc: recipient(s)
if ( $this->bcc ) {
$this->headers .= "Bcc: " . $this->bcc . "\n";
}
return mail ( $this->to, $this->subject, $this->message, $this->headers );
}
}
}
?>
////////////////////////////////////////////////////////////
// EmailClass 0.5
// class for sending mail
//
// Paul Schreiber
// php@paulschreiber.com
// http://paulschreiber.com/
//
// parameters
// ----------
// - subject, message, senderName, senderEmail and toList are required
// - ccList, bccList and replyTo are optional
// - toList, ccList and bccList can be strings or arrays of strings
// (those strings should be valid email addresses
//
// example
// -------
// $m = new email ( "hello there", // subject
// "how are you?", // message body
// "paul", // sender's name
// "foo@foobar.com", // sender's email
// array("paul@foobar.com", "foo@bar.com"), // To: recipients
// "paul@whereever.com" // Cc: recipient
// );
//
// print "mail sent, result was" . $m->send();
//
//
//
if ( ! defined( 'MAIL_CLASS_DEFINED' ) ) {
define('MAIL_CLASS_DEFINED', 1 );
class email {
// the constructor!
function email ( $subject, $message, $senderName, $senderEmail, $toList, $ccList=0, $bccList=0, $replyTo=0) {
$this->sender = $senderName . " <$senderEmail>";
$this->replyTo = $replyTo;
$this->subject = $subject;
$this->message = $message;
// set the To: recipient(s)
if ( is_array($toList) ) {
$this->to = join( $toList, "," );
} else {
$this->to = $toList;
}
// set the Cc: recipient(s)
if ( is_array($ccList) && sizeof($ccList) ) {
$this->cc = join( $ccList, "," );
} elseif ( $ccList ) {
$this->cc = $ccList;
}
// set the Bcc: recipient(s)
if ( is_array($bccList) && sizeof($bccList) ) {
$this->bcc = join( $bccList, "," );
} elseif ( $bccList ) {
$this->bcc = $bccList;
}
}
// send the message; this is actually just a wrapper for
// PHP's mail() function; heck, it's PHP's mail function done right :-)
// you could override this method to:
// (a) use sendmail directly
// (b) do SMTP with sockets
function send () {
// create the headers needed by PHP's mail() function
// sender
$this->headers = "From: " . $this->sender . "\n";
// reply-to address
if ( $this->replyTo ) {
$this->headers .= "Reply-To: " . $this->replyTo . "\n";
}
// Cc: recipient(s)
if ( $this->cc ) {
$this->headers .= "Cc: " . $this->cc . "\n";
}
// Bcc: recipient(s)
if ( $this->bcc ) {
$this->headers .= "Bcc: " . $this->bcc . "\n";
}
return mail ( $this->to, $this->subject, $this->message, $this->headers );
}
}
}
?>
最新技术文章: