php邮件读取:
程序开发的思路:mail文件:先连接到pop3,读取用户的邮件列表,判断邮件是否读取过,如果没读取过就把邮件加到中转的数据库中。get_mail()函数,读取数据库中的邮件列表,读完后对数据库进行清除。以便能一直读取的都是新的邮件。
代码程序:mail文件:
header("content-type:text/html; charset=utf-8");
include 'config.php';
include 'Pop3.php';
include 'mail_config.php';
$conn=mysql_connect($db_host,$db_user,$db_pass);
mysql_query("set names utf8");
mysql_select_db("$mail_data",$conn);
$pop3=new Net_POP3();
if ($pop3->connect($host,110)=="true"){
$bool=$pop3->login($user,$password);
if ($bool=="ture"){
$list=$pop3->_cmdList();
$sum=$pop3->_cmdStat();
echo "<br>";
for ($j=0;$j<$sum[0];$j++){
$head=$pop3->getParsedHeaders($list[$j]['msg_id']);
preg_match("/([a-z0-9A-Z\s]+):([0-9]+):([0-9]+)/",$head['Date'],$rt);
echo "<br>";
&nbs ......
<?php
header("content-type:text/html; charset=UTF-8");
/*
* record kid words and insert into database
* user by sending email to publication kid words
*
*/
include 'POP3.php';
include 'email_class.php';
include 'Mail_mimeDecode.php';
//include 'include/compatible.php';
include 'include/extend_common.php';
//include '../../htdocs/include/extend_common.php';
define('POST_from_EMAIL', 1);
define('DATABASE_CONNECTION_ERROR', 2);//数据库连接失败错误
define('EMAIL_CONNECTION_ERROR', 3);//邮箱连接失败错误
define('ACCOUNT_ERROR', 4);//邮箱的账号错误
define('SIGN_EMAIL_ERROR', 5);//邮件标记删除错误
define('DELELET_ERROR', 6);//删除邮件错误
define('INSERT_ERROR', 7);//插入数据失败错误
class mail_data {
function mail_data(){
include 'config.php';
$mail_log=fopen("mail_log.txt","a+");
&nbs ......
1.如果一个方法能被静态,那就声明他为静态的,速度可提高1/4;
2.echo的效率高于print,因为echo没有返回值,print返回一个整型;
3.在循环之前设置循环的最大次数,而非在在循环中;
4.销毁变量去释放内存,特别是大的数组;
5.避免使用像__get, __set, __autoload等魔术方法;
6.requiere_once()比较耗资源;
7.在includes和requires中使用绝对路径,这样在分析路径花的时间更少;
8.如果你需要得sexinsex到脚本执行时的时间,$_SERVER['REQUSET_TIME']优于time();
9.能使用字符处理函数的,尽量用他们,因为效率高于正则;//php100.com
10.str_replace字符替换比正则替换preg_replace快,但strtr比str_replace又快1/4;
11.如果一个函数既能接受数组又能接受简单字符做为参数,例如字符替换,并且参数列表不是太长,可以考虑多用一些简洁的替换语句,一次只替换一个字符,而不是接受数组做为查找和替换参数。大事化小,1+1>2;
12.用@掩盖错误会降低脚本运行速度;
13.$row['id']比$row[id]速度快7倍,建议养成数组键加引号的习惯;
14.错误信息很有用;
15.在循环里别用函数,例如For($x=0; $x < count($ ......
近日因公司开发需要,在本机Win7下架设了Apache+MySql+PHP
所使用PHP版本:PHP5.3.0, 之后发现无法连接mysql数据库,均报超时错误:
PHP Warning: mysqli::mysqli(): [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in xxx.php on line x
PHP Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
in xxx.php on line x
在网站上查找了很久,均没有有效的解决办法.
后来在国外的网上查到此原因与windows的hosts文件有关
对如下进行修改:
# 127.0.0.1 localhost
#:: 1 localhost
修改为
127.0.0.1 localhost
#:: localhost
问题解决 ......
<?php
$HotSong="爱情转移|菊花台|离歌|月亮之上|隐形的翅膀|中国话|求佛|秋天不回来|发现爱|难道爱一个人有错吗|千里之外|连哭都是我的错";
function HotSo($HotSong){
$HotSo='';
echo($HotSong);
$b=explode('|',$HotSong);
foreach ($b as $v) {
$HotSo.="<a href="song.php?song=".urlencode($v)."" mce_href="song.php?song=".urlencode($v)."">" .$v. "</a> ";
}
return $HotSo;
}
echo HotSo($HotSong);
?> ......
smarty作为PHP的模板,实现了前台美工与后台逻辑的分离。前一段时间简单地学了一下,把其安装于配置以及内部的语法来简单总结一下。然后要设计一下电子商务系统。
smarty压缩包解压后,在libs文件夹下,有2个目录和4个文件,2个文件夹分别是internals和plugins,4个文件依次是debug,smarty.class,config_file.class,smarty_compiler.class。这2个目录和4个文件需要拷入安装目录。安装完成后,需要建一个smarty的配置文件,一般命名为smarty_config.php,内部代码需要定义smarty的编译目录等等。代码一般如下
<?php
include "class/Smarty.class.php";
define('__SITE_ROOT', 'd:/appserv/web/demo'); // 最后没有斜线
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$tpl->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
$tpl->left_delimiter = '<{';
$tpl->right_delimiter = '}>';
?>
包括设置模板目录,编译目录,左右分隔符等等。 ......