<?php教程
$doc = new DOMDocument();
$doc->load( 'books.xml' );
$books = $doc->getElementsByTagName( "book" );
foreach( $books as $book )
{
$authors = $book->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$publishers = $book->getElementsByTagName( "publisher" );
$publisher = $publishers->item(0)->nodeValue;
$titles = $book->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
echo "$title - $author - $publisher ";
echo "<br>";
}
?>
xml文件
<books>
<book>
<author>Jack Herrington</author>
<title>PHP Hacks</title>
<publisher>O'Reilly</publisher>
</book>
<book>
<author>Jack Herrington</author>
<title>Podcasting Hacks</title>
<publisher>O'Reilly</publisher>
</book>
</books>
if(send_mail('test@qq.com','邮件主题','邮件内容')==""){
echo "发送成功!<br>";
} else{
echo "发送失败!<br>";
}
<?php
$to = "test@test.com";
$subject = "Test Subject";
$message = "This is the test email.";
$from = "youremail@yourdomain.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
?>
<?php
function send_mail($to, $subject = 'No subject', $body) {
$loc_host = "im286"; //发信计算机名,可随意
$smtp_acc = "test@126.com"; //Smtp认证的用户名
$smtp_pass="******"; //Smtp认证的密码,一般等同pop3密码
$smtp_host="smtp.126.com"; //SMTP服务器地址,类似 smtp.tom.com
$from="test@126.com"; //发信人Email地址,你的发信信箱地址
$headers = "Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64";
$lb=" "; //linebreak
$hdr=explode($lb,$headers); //解析后的hdr
if($body){$bdy = preg_replace("/^./","..",explode($lb,$body));}//解析后的Body
$smtp = array(
//1、EHLO,期待返回220或者250
array("EHLO ".$loc_host.$lb,"220,250","HELO error: "),
//2、发送Auth Login,期待返回334
array("AUTH LOGIN".$lb,"334","AUTH error:"),
//3、发送经过Base64编码的用户名,期待返回334
array(base64_encode($smtp_acc).$lb,"334","AUTHENTIFICATION error : "),
//4、发送经过Base64编码的密码,期待返回235
array(base64_encode($smtp_pass).$lb,"235","AUTHENTIFICATION error : "));
//5、发送Mail From,期待返回250
$smtp[] = array("MAIL FROM: <".$from.">".$lb,"250","MAIL FROM error: ");
//6、发送Rcpt To。期待返回250
$smtp[] = array("RCPT TO: <".$to.">".$lb,"250","RCPT TO error: ");
//7、发送DATA,期待返回354
$smtp[] = array("DATA".$lb,"354","DATA error: ");
//8.0、发送From
$smtp[] = array("From: ".$from.$lb,"","");
//8.2、发送To
$smtp[] = array("To: ".$to.$lb,"","");
//8.1、发送标题
$smtp[] = array("Subject: ".$subject.$lb,"","");
//8.3、发送其他Header内容
foreach($hdr as $h) {$smtp[] = array($h.$lb,"","");}
//8.4、发送一个空行,结束Header发送
$smtp[] = array($lb,"","");
//8.5、发送信件主体
if($bdy) {foreach($bdy as $b) {$smtp[] = array(base64_encode($b.$lb).$lb,"","");}}
//9、发送“.”表示信件结束,期待返回250
$smtp[] = array(".".$lb,"250","DATA(end)error: ");
//10、发送Quit,退出,期待返回221
$smtp[] = array("QUIT".$lb,"221","QUIT error: ");
//打开smtp服务器端口
$fp=@fsockopen($smtp_host, 25);
if(!$fp) echo "<b>Error:</b> Cannot conect to ".$smtp_host."<br>";
while($result = @fgets($fp, 1024)){if(substr($result,3,1) == " ") { break; }}
$result_str="";
//发送smtp数组中的命令/数据
foreach($smtp as $req){
//发送信息
@fputs($fp, $req[0]);
//如果需要接收服务器返回信息,则
if($req[1]){
//接收信息
while($result = @fgets($fp, 1024)){
if(substr($result,3,1) == " ") { break; }
};
if (!strstr($req[1],substr($result,0,3))){
$result_str.=$req[2].$result."<br>";
}
}
}
//关闭连接
@fclose($fp);
return $result_str;
}
?>
1。__construct()
实例化对象时被调用,
当__construct和以类名为函数名的函数同时存在时,__construct将被调用,另一个不被调用。
2。__destruct()
当删除一个对象或对象操作终止时被调用。
3。__call()
对象调用某个方法,
若方法存在,则直接调用;
若不存在,则会去调用__call函数。
4。__get()
读取一个对象的属性时,
若属性存在,则直接返回属性值;
若不存在,则会调用__get函数。
5。__set()
设置一个对象的属性时,
若属性存在,则直接赋值;
若不存在,则会调用__set函数。
6。__toString()
打印一个对象的时被调用。如echo $obj;或print $obj;
7。__clone()
克隆对象时被调用。如:$t=new Test();$t1=clone $t;
8。__sleep()
serialize之前被调用。若对象比较大,想删减一点东东再序列化,可考虑一下此函数。
9。__wakeup()
unserialize时被调用,做些对象的初始化工作。
10。__isset()
检测一个对象的属性是否存在时被调用。如:isset($c->name)。
11。__unset()
unset一个对象的属性时被调用。如:unset($c->name)。
12。__set_state()
调用var_export时,被调用。用__set_state的返回值做为var_export的返回值。
13。__autoload()
实例化一个对象时,如果对应的类不存在,则该方法被调用。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.111cn.net/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php教程 增加数据保存到mysql教程数据实例教程</title>
<style type="text/css教程">
<!--
body {
margin-left: 0px;
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
}
td{
padding:2px;
}
body,td,th {
font-size: 12px;
}
-->
</style></head>
<body>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#F2F2F2" >
<form id="form1" name="form1" method="post" action=""><tr>
<td width="15%" height="26" align="center" bgcolor="#FFFFFF">标 题:</td>
<td width="85%" bgcolor="#FFFFFF">
<label>
<input type="text" name="title" />
</label> </td>
</tr>
<tr>
<td height="26" align="center" bgcolor="#FFFFFF">关键词:</td>
<td bgcolor="#FFFFFF"><label>
<input name="keyword" type="text" id="keyword" size="50" />
</label></td>
</tr>
<tr>
<td height="26" align="center" bgcolor="#FFFFFF">描 述:</td>
<td bgcolor="#FFFFFF"><label>
<textarea name="desc" cols="50" rows="4" id="desc"></textarea>
</label></td>
</tr>
<tr>
<td height="26" align="center" bgcolor="#FFFFFF">说明简介:</td>
<td bgcolor="#FFFFFF"><label>
<textarea name="body" cols="80" rows="8"></textarea>
</label></td>
</tr>
<tr>
<td height="26" align="center" bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><label>
<input type="submit" name="Submit" value="保存数据" />
</label></td>
</tr>
</form>
</table>
<?php
if( $_POST )
{
mysql_connect('localhost','root','root');
mysql_select_db('fangke_cc');
mysql_query("set names 'gbk'");
$title = htmlspecialchars(isset($_POST['title'])?$_POST['title']:'');
$keyword = htmlspecialchars(isset($_POST['keyword'])?$_POST['keyword']:'');
$desc = htmlspecialchars(isset($_POST['desc'])?$_POST['desc']:'');
$body = htmlspecialchars(isset($_POST['body'])?$_POST['body']:'');
if( $title == "" || strlen( $title ) > 200 )
{
exit('<script>alert("标题不合法,重新输入信息");history.back();</script>');
}
else if( $body == "" || strlen( $body ) >2048 )
{
exit('<script>alert("内空太长,重新输入信息");history.back();</script>');
}
else
{
$time = time();
$body=preg_replace("/$title/","<h1>".$title."</h1>",$body,1);
$sql = "insert into su_zt(title,description,keyword,body,datetimes) values('$title','$desc','$keyword','$body','$time')";
mysql_query( $sql ) or die(mysql_error().$sql);
die('<script>alert("保存成功");location="'.$_SERVER['HTTP_REFERER'].'";</script>');
}
}
?>
su_zt表结构
CREATE TABLE IF NOT EXISTS `su_zt` (
`id` int(8) NOT NULL auto_increment,
`title` varchar(200) character set gb2312 default NULL,
`keyword` varchar(60) character set gb2312 default NULL,
`description` text character set gb2312,
`body` text character set gb2312,
`datetimes` int(4) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
</body>
</html>
本站原创教程,转载注明来源http://www.111cn.net,否则必究
*/
class getromatePic{
var $savaDir ='pic/';
var $filePath ='http://www.111cn.net/banner/banner.gif';
var $fileName ='111cn.net.gif';
function __construct() {
$this->isdir();
}
function isdir()
{
if( !is_dir( $this->savaDir ) )
{
if( ! mkdir( $this->savaDir ) )
{
exit('目录不存并且没有写的权限');
}
}
$this->autoGetRemoteFile();
}
function autoGetRemoteFile()
{
$content = file_get_contents($this->filePath);
if( $content )
{
$hold = fopen($this->savaDir.$this->fileName,'w+');
if( fwrite($hold,$content) )
{
echo '图片自动采集成功';
fclose($hold);
}
else
{
echo '保存失败';
}
}
else
{
echo '远程图路不正确';
}
}
}
//类调用方法
new getromatePic();
//由于使用的构造函数所以我们只需要创建类,其它的会自动执行,
//本文章原创于www.111cn.net转载必须注明出处,否则必究。