mysql教程_connect('localhost','root','root');
mysql_select_db('dfd');
$array = file("ip.txt");
foreach( $array as $k )
{
list ($ip,$s) = explode('/',$k);
$ipe = str_replace('.0','.255',$ip);
$ipint = iptoint($ip);
$ipinte = iptoint($ipe);
//echo iptoint($ip) .'-'.iptoint($ipe),'<br />';
$s = array($ip,$ipe,$ipint,$ipinte);
save($s);
}
function iptoint($ip)
{
$ipa=explode(".",$ip);
$ipn=$ipa[0]*16777216+$ipa[1]*65536+$ipa[2]*256+$ipa[3];
return $ipn;
}
function save($arr)
{
if( count( $arr ) >3 )
{
print_r($arr);
mysql_query("insert into ip(ips教程,ipe,ipsint,ipeint)values('".$arr[0]."','".$arr[1]."','".$arr[2]."','".$arr[3]."')") or die(mysql_error());
}
}
在 linux下,可以使用crontab + php教程的方法:
1、使用crontab –e编辑定时任务
内容为:
xx:xx:xx 执行一个test.php文件
2、php文件必须在文件头一行,加上解释器路径(就象perl做的那样)
#!/usr/local/bin/php
php的执行需要apache的支持,shell脚本的执行需要linux的支持,而linux支持定时运行某个程序的功能
---------------------------------------------------------------
将php作为shell脚本语言使用(转载)
--英文原著:darrell brogdon,发表于 http://www.phpbuilder.com/columns/darrell20000319.php3)
可能很多人都想过使用php编写一些定时发信之类的程序,但是却没有办法定时执行php;一次去phpbuilder的时候,发现了这一篇文章,于是想给大家翻译一下(同时做了一些修改),希望对大家有用。
----------------------------------------------------------------------------------
今天我们来讲一下关于php mvc模板的zend使用方法与配置实例,这是一款从zend加载 config文件到加载数据库 getinstance()方法用来获取前端控制器实例 加载smarty模板插件等简单的配置方法。
*/
//指明引用文件的路径
set_include_path('.' .
path_separator . './libary/'. //指定zend所在目录
path_separator . './application/models/'. //指定model所在目录
path_separator . './libary/smarty/'.
path_separator . get_include_path());
//必须手动加载loader.php
include "zend/loader.php";
zend_loader::registerautoload();
//加载数据库配置文件
//zend/config/ini.php
$config = new zend_config_ini ('./application/config.ini', 'general');
$registry = zend_registry::getinstance();
$registry->set('config', $config);
//
$db = zend_db::factory ($config->db);
$db->query('set names gbk');
zend_db_table::setdefaultadapter($db);
//getinstance()方法用来获取前端控制器实例
$frontcontroller = zend_controller_front::getinstance();
//指定模块目录
$frontcontroller->addmoduledirectory('./application');
//加载smarty模板插件
$frontcontroller->registerplugin(new plugin_myplugin());
//zend布局应用
//$options = array("layout"=>"head","layoutpath"=>"/layouts", 'contentkey' => 'content');
//$layout = new zend_layout($options);
//设置模板后缀名
$viewrenderer = zend_controller_action_helperbroker::getstatichelper('viewrenderer');
$viewrenderer->setviewsuffix('php');
//抛出异常
$frontcontroller->throwexceptions(true);
//开始运行程序
$frontcontroller->dispatch();
?>
if ($http_cookie_vars["vote"]) {
echo "<script>alert('您已经投过票了,请不要重复投票');history.back();</script>";
exit;
}
$vcount=$_post["vcount"];
$lld=$_post["jump"];
$tys=$_post["tys"];
if (!$vcount) {
echo "<script>alert('您还没有选择任何投票项目');history.back();</script>";
exit;
}
$db=@mysql_connect("localhost","root","root") or die("数据库教程连接失败");
mysql_select_db("vote",$db);
if ($vcount&&$lld) {
if ($tys=="1") {
$sql="update vote set vcount=vcount+1 where id=$vcount";
$result=mysql_query($sql,$db);
setcookie("vote","vote",time()+3600);
echo "<script>alert('投票成功!');location.href='vote.php?id=$lld';</script>";
}
else {
for ($i=0;$i<sizeof($vcount);$i++) {
$sql1="update vote set vcount=vcount+1 where id=$vcount[$i]";
$result1=mysql_query($sql1,$db);
}
setcookie("vote","vote",time()+3600);
echo "<script>alert('投票成功!');location.href='vote.php?id=$lld';</script>";
}
}
php教程 匹配中文字符的正则表达式
匹配中文字符的正则表达式: [u4e00-u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了
匹配双字节字符(包括汉字在内):[^x00-xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ascii字符计1)
*/
$str = "singlepoint单点日志";
if (preg_match("/^[x{4e00}-x{9fa5}]+$/u",$str)) {
print("该字符串全部是中文");
} else {
print("该字符串不全部是中文");
}
$alias_len = mb_strlen($value['alias'], "utf-8");
$temp_array = array();
for($i = 0;$i<$alias_len; $i++)
{
$temp_array[$i] = mb_substr($value['alias'],$i,1,"utf-8");
if(ord(substr($temp_array[$i],0,1))>'0xe0' && strlen($temp_array[$i])<3)
$temp_array[$i] = '';
}
$value['alias'] = implode('',$temp_array);