php 关键字百度排名批量查
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>关键字百度排名批量查</title>
<base target="_blank" />
<meta http-equiv="x-ua-compatible" content="ie=emulateie7" />
<style type="text/css教程">
body{margin:0;padding:0;background:#fff;color:#000;font:12px 微软雅黑, verdana, tahoma, lucida grande, arial, sans-serif;text-align:center;}
#wrapper{width:990px;margin:0 auto;line-height:20px;text-align:left;}
#header,#main,#footer{clear:both;float:left;margin:10px 0 0 0;width:100%;}
a,a:visited{color:#0196e3;text-decoration:none;}
form{margin:10px;}
.kinput{width:300px;margin:0 5px;padding:2px;text-align:left;border:1px solid #ccc;font-weight:bold;}
.kbutton{width:80px;margin:0 5px;padding:2px;height:20px;}
#kgrid{float:left;width:100%;}
.s_kw,.s_rank,.s_wt,.s_title,.s_cache,.s_feng,.s_baidu,.s_mu{float:left;height:30px;line-height:30px;overflow:hidden;text-align:left;border:1px solid #c2d5e3;}
.s_bar{clear:both;float:left;width:100%;height:30px;line-height:30px;text-align:center;}
.s_kw{clear:both;width:120px;}
.s_rank{width:30px;}
.s_wt{width:50px;color:#0e774a;}
.s_title{width:340px;}
.s_cache{width:80px;}
.s_feng{width:80px;}
.s_baidu{width:150px;}
.s_mu{width:120px;}
</style>
</head><body>
<div id="wrapper">
<?php教程
function tongji()
{
$myhost = $_server['http_host'];
if (preg_match("/(www.)?baiek.com/i", $myhost, $myout))
{
echo '<script language="网页特效" type="text/javascript" src="http://js.users.51.la/4295418.js"></script>';
}
}function libxml_display_error($error)
{
$return = "<br/>n";
switch ($error->level)
{
case libxml_err_warning:
$return .= "<b>warning $error->code</b>: ";
break;
case libxml_err_error:
$return .= "<b>error $error->code</b>: ";
break;
case libxml_err_fatal:
$return .= "<b>fatal error $error->code</b>: ";
break;
}
$return .= trim($error->message);
if ($error->file)
{
$return .= " in <b>$error->file</b>";
}
$return .= " on line <b>$error->line</b>n";
return $return;
}function libxml_display_errors()
{
$errors = libxml_get_errors();
foreach ($errors as $error)
{
print libxml_display_error($error);
}
libxml_clear_errors();
}$kfname = '';
if (isset($_get['kf']))
{
$kfname = trim($_get['kf']);
}
$version = '<script language="javascript" type="text/javascript" src="http://www.111cn.net/version.js"></script>';
echo <<< eoth
<div id="header">
做企业站或认识企业站的朋友,请支持一下我的小站 <a href="http://www.198114.com/"><b>198114产品企业分类目录</b></a>,多谢多谢!!
<a href="http://www.111cn.net/" target="_self"><h1>关键字百度排名批量查询(php网页版) baiek.com</h1></a>
<form method="get" target="_self">
<input id="kf" name="kf" type="text" class="kinput" value="{$kfname}" />
<input id="submitbtn" type="submit" class="kbutton" value="批量查询" />
 <a href="http://www.111cn.net/baiek.rar" target="_self"><b>点击此处下载(更新于{$version})</b></a>
 在线演示:<a href="http://www.111cn.net/?kf=kw1.xml" target="_self">演示1</a> <a href="http://www.111cn.net/?kf=kw2.xml" target="_self">演示2</a> <a href="http://www.111cn.net/?kf=kw3.xml" target="_self">演示3</a>
</form>
</div>eoth;
if (!file_exists($kfname) || !is_readable($kfname))
{
tongji();
exit('请输入正确的关键字清单文件(xml格式,请参考<a href="http://www.111cn.net/readme.txt">readme</a>文件)!!');
}
libxml_use_internal_errors(true);
$doc = new domdocument();
$doc->load($kfname);
if (!$doc->schemavalidate('kw.xsd'))
{
print '<b>关键字列表xml文件发现错误!</b>';
libxml_display_errors();
tongji();
exit;
}//由xml文件提取关键字列表与相应的域名
$kwlist = array(); $g = 1;
$kgroups教程 = $doc->getelementsbytagname("kgroup");
foreach ($kgroups as $kgroup)
{
$kwlist[$g]['domain'] = trim($kgroup->getelementsbytagname("kdomain")->item(0)->nodevalue);
$kwords = $kgroup->getelementsbytagname("kword");
$w = 1;
foreach ($kwords as $kword)
{
if ($kword->haschildnodes())
{
$kwlist[$g]['kword'][$w] = trim($kword->firstchild->nodevalue);
}
$w++;
}
$g++;
}
?>
<div id="main">
<?php
function get_dm_weight($h, $i)
{
//$h表示搜索结果的url,$i表示结果排名
$p = ceil($i / 10); //搜索结果第几页
$i_weight = array(1 => 52, 2 => 15, 3 => 10, 4 => 5, 5 => 5, 6 => 4, 7 => 1, 8 => 3, 9 => 2, 0 => 3);
$h_str = preg_replace("/^.*?://(.*?)(#.*)?$/i", "$1$3", $h); //去除url中的协议(例如http)与#信息片段部分
$h_arr = explode("?", $h_str, 2);
$h0_arr = explode("/", $h_arr[0]);
if ($h0_arr[count($h0_arr) - 1] == '')
{
$level_l = count($h0_arr) - 1;
}
else
{
$level_l = count($h0_arr);
}
if (isset($h_arr[1]))
{
if ($h_arr[1] != '')
{
$level_r = count(explode("&", $h_arr[1]));
}
else
{
$level_r = 0;
}
}
else
{
$level_r = 0;
}
$dw = $i_weight[$i % 10] * pow(0.5, ($level_l + $level_r - 1)) * 9 / pow(10, $p);
return number_format($dw, 1);;
}function fetch_baidu($d, $k)
{
$urlw = urlencode(iconv("utf-8","gbk//ignore",$k));
$max_srh_page = 2; //百度搜索结果50条/页,提取2页,也就是只在前100条搜索结果中检查排名,最大值可以设为16
$baidu_ids = array(); //存储百度系列子站点占据的排名位置
$baidu_mus = array(); //存储百度开放平台等优质站点占据的排名位置
$isrank = 0; //$isrank = 1 当前域名下这个关键词获得排名; $isrank = 0 当前域名下这个关键词没有排名
$all_count = 0; //测试变量,以确认匹配规则不会遗漏任何一条搜索结果
$dm_weight = 0; //分析搜索结果页面中顶级、次级、目录、内页的情况,粗略反映一个关键字的竞争激烈程度,非常不准,仅供参考
for ($page_no = 1; $page_no <= $max_srh_page; $page_no++)
{
if ($page_no > 16) break;
$fail_try = 1;
$pn = ($page_no - 1) * 50;
$url = "http://www.baidu.com/s?wd={$urlw}&pn={$pn}&rn=50";
$snoopy = new snoopy;
// $snoopy->proxy_host = "127.0.0.1"; //采集可选代理ip,以免频繁抓百度反被百度咬
// $snoopy->proxy_port = "80"; //proxy代理所用端口
$snoopy->fetch($url);
$contents = iconv("gbk","utf-8//ignore",$snoopy->results);
unset($snoopy);
// echo $contents;
if (!preg_match("/<span>此内容系百度根据您的指令自动搜索的结果/i",$contents,$out))
{
if ($fail_try > 5)
{
continue;
}
else
{
$fail_try++;
$page_no--;
sleep(30);
continue;
}
}
if (!isset($ebaidu))
{
$ebaidu = array('lt' => 0, 'lb' => 0, 'r' => 0); //记录百度推广数量,分为左上、左下、右侧
if (preg_match_all("/<tr><td class="f ec_pp"><a id="awd+"/i", $contents, $out_lt))
{
$ebaidu['lt'] = count($out_lt[0]);
}
if (preg_match_all("/<table id="40d+".*?class="ec_mr15">/i", $contents, $out_lt))
{
$ebaidu['lt'] = count($out_lt[0]);
}
if (preg_match_all("/<table width="65%".*?class="ec_mr15">/i", $contents, $out_lb))
{
$ebaidu['lb'] = count($out_lb[0]);
}
if (preg_match_all("/<div id="bdfsd+" class="ec_pp".*?><a id=dfsd+/i", $contents, $out_r))
{
$ebaidu['r'] = count($out_r[0]);
}
}
if (preg_match_all("/((<table cellpadding="0" cellspacing="0".*?id="(d+)" mu="(.*?)">)|(<table id="(d+)" cellpadding="0" cellspacing="0" mu="(.*?)">))[s|s]*?((<a.*?href=".*?".*?>(.*?)</a>)|(<div id="app_.*?"></div>))/i", $contents, $out_mu))
{
foreach ($out_mu[0] as $om_key => $om_val)
{
$om_id1 = $out_mu[3][$om_key];
$om_href1 = $out_mu[4][$om_key];
$om_id2 = $out_mu[6][$om_key];
$om_href2 = $out_mu[7][$om_key];
$om_title = strip_tags($out_mu[10][$om_key]);
$baidu_mus[] = $om_id1 . $om_id2;
$dm_weight = $dm_weight + get_dm_weight($om_href1 . $om_href2, $om_id1 . $om_id2);
if (preg_match("/://(w*?.)*?baidu.com//i", $om_href1 . $om_href2, $om_domain))
{
$baidu_ids[] = $om_id1 . $om_id2;
}
if (preg_match("/://(w*?.)*?{$d}//i", $om_href1 . $om_href2, $om_domain))
{
echo '<div style="clear:both"></div><span class="s_kw"><a href="http://www.baidu.com/s?wd=' . $urlw . '">' . $k . '</a></span><span class="s_rank">' . $om_id1 . $om_id2 . '</span><span class="s_wt"></span><span class="s_title"><a href="' . $om_href1 . $om_href2 . '">' . $om_title . '</a></span><span class="s_cache"></span>';
$isrank = 1;
}
}
}
if (preg_match_all("/<table cellpadding="0" cellspacing="0" class="result" id="(d+)"><tr><td class=f><h3 class="t">(<font.*?</font>)?<a.*?href="(.*?)" target="_blank">(.*?)</a></h3><font size=-1>.*?<span class="g">.*? ((d{4}-d{1,2}-d{1,2})|(d+小时前)|(d+分钟前)) .*?</span>.*?<br></font></td></tr></table>/i", $contents, $out_all))
{
foreach ($out_all[0] as $o_key => $o_val)
{
$o_id = $out_all[1][$o_key];
$o_href = $out_all[3][$o_key];
$o_title = strip_tags($out_all[4][$o_key]);
$o_cache = $out_all[6][$o_key] . $out_all[7][$o_key] . $out_all[8][$o_key];
$dm_weight = $dm_weight + get_dm_weight($o_href, $o_id);
if (preg_match("/://(w*?.)*?baidu.com//i", $o_href, $o_domain))
{
$baidu_ids[] = $o_id;
}
if (preg_match("/://(w*?.)*?{$d}//i", $o_href, $o_domain))
{
echo '<div style="clear:both"></div><span class="s_kw"><a href="http://www.baidu.com/s?wd=' . $urlw . '">' . $k . '</a></span><span class="s_rank">' . $o_id . '</span><span class="s_wt">' . $dm_weight . '%</span><span class="s_title"><a href="' . $o_href . '">' . $o_title . '</a></span><span class="s_cache">' . $o_cache . '</span>';
$isrank = 1;
}
}
}
//$all_count用来检查上述正则匹配是否匹配到所有搜索结果,特别关注百度系列站点、百度开放平台以及百度应用等有别于普通搜索结果
if (isset($out_mu[0])) $all_count = $all_count + count($out_mu[0]);
if (isset($out_all[0])) $all_count = $all_count + count($out_all[0]);
// echo '<br />总共找到' . $all_count . '个匹配<br />';
if (!preg_match("/<a href="s?wd=.*?>下一页</a>.*?</p>/i",$contents,$out))
{
break;
}
}
if (count($baidu_mus) >= 1)
{
$bmus = implode(",", $baidu_mus);
}
else
{
$bmus = '';
}
if (count($baidu_ids) >= 1)
{
$bids = implode(",", $baidu_ids);
}
else
{
$bids = '';
}
if ($isrank == 1)
{
echo '<span class="s_feng">上' . $ebaidu['lt'] . '下' . $ebaidu['lb'] . '右' . $ebaidu['r'] . '</span><span class="s_baidu">' . $bids . '</span><span class="s_mu">' . $bmus . '</span>';
}
else
{
echo '<div style="clear:both"></div><span class="s_kw"><a href="http://www.baidu.com/s?wd=' . $urlw . '">' . $k . '</a></span><span class="s_rank">0</span><span class="s_wt">' . $dm_weight . '%</span><span class="s_title"></span><span class="s_cache"></span><span class="s_feng">上' . $ebaidu['lt'] . '下' . $ebaidu['lb'] . '右' . $ebaidu['r'] . '</span><span class="s_baidu">' . $bids . '</span><span class="s_mu">' . $bmus . '</span>';
}
unset($ebaidu);
}
//逐个域名与关键字采集百度排名信息并显示
set_include_path(".");
include "snoopy.class.php";
set_time_limit(0);
ob_flush(); flush(); ob_end_clean(); ob_implicit_flush(1);
echo '<div id="kgrid">';
echo '<span class="s_kw">关键字</span><span class="s_rank">排名</span><span class="s_wt">竞争度</span><span class="s_title">网页标题</span><span class="s_cache">百度快照</span><span class="s_feng">百度推广数量</span><span class="s_baidu">百度占位</span><span class="s_mu">百度mu占位</span>';
foreach ($kwlist as $d_ks)
{
$dm = $d_ks['domain'];
echo '<div style="clear:both"></div><span class="s_bar">域名:' . $dm . '</span>';
foreach ($d_ks['kword'] as $k)
{
fetch_baidu($dm, $k);
}
}
echo '</div>';
?>
</div><!--div main end-->
</div><!--div wrap end-->
<?php
tongji();
?>
</body>
</html>
php教程文件缓存实例代码
缓存在实际使用当中应用很广泛,可以减轻对服务器数据库教程的访问,提高运行速度。目前很多cms内容管理系统中频繁使用缓存机制来提高系统运行的效率
cache.php 代码如下:
php代码
<?
/*
用户需要事先定义的常量:
_cachepath_ 模板缓存路径
_cacheenable_ 自动缓存机制是否开启,未定义或为空,表示关闭自动缓存机制
_recachetime_ 自动重新缓存间隔时间,单位为秒,未定义或为空,表示关闭自动重新缓存
*/
class cache {
var $cachefile;
var $cachefilevar;
function cache() {
//生成当前页的cache组文件名 $this->cachefilevar 及文件名 $this->cachefile
//动态页的参数不同对应的cache文件也不同,但是每一个动态页的所有cache文件都有相同的文件名,只是扩展名不同
$s=array(".","/");$r=array("_","");
$this->cachefilevar=str_replace($s,$r,$_server["script_name"])."_".$_get[_actionvar_];
$this->cachefile=$this->cachefilevar.".".md5($_server["request_uri"]);
}
//删除当前页/模块的缓存
function delete() {
//删除当前页的缓存
$d = dir(_cachepath_);
$strlen=strlen($this->cachefilevar);
//返回当前页的所有cache文件组
while (false !== ($entry = $d->read())) {
if (substr($entry,0,$strlen)==$this->cachefilevar) {
if (!unlink(_cachepath_."/".$entry)) {echo "cache目录无法写入";exit;}
}
}
}
//判断是否已cache过,以及是否需要cache
function check() {
//如果设置了缓存更新间隔时间 _recachetime_
if (_recachetime_+0>0) {
//返回当前页cache的最后更新时间
$var=@file(_cachepath_."/".$this->cachefilevar);$var=$var[0];
//如果更新时间超出更新间隔时间则删除cache文件
if (time()-$var>_recachetime_) {
$this->delete();$ischage=true;
}
}
//返回当前页的cache
$file=_cachepath_."/".$this->cachefile;
//判断当前页cache是否存在 且 cache功能是否开启
return (file_exists($file) and _cacheenable_ and !$ischange);
}
//读取cache
function read() {
//返回当前页的cache
$file=_cachepath_."/".$this->cachefile;
//读取cache文件的内容
if (_cacheenable_) return readfile($file);
else return false;
}
//生成cache
function write($output) {
//返回当前页的cache
$file=_cachepath_."/".$this->cachefile;
//如果cache功能开启
if (_cacheenable_) {
//把输出的内容写入cache文件
fopen($file,'w'">$fp=@fopen($file,'w');
if (!@fputs($fp,$output)) {echo "模板cache写入失败";exit;}
@fclose($fp);
//如果设置了缓存更新间隔时间 _recachetime_
if (_recachetime_+0>0) {
//更新当前页cache的最后更新时间
$file=_cachepath_."/".$this->cachefilevar;
$fp=@fopen($file,'w');
if (!@fwrite($fp,time())) {echo "cache目录无法写入";exit;}
@fclose($fp);
}
}
}
}
?>
使用过程:
php代码
<?php
define("_cachepath_","./cache/");
define("_cacheenable_","1");
define("_recachetime_","43200");
include('cache.php');
$cache=new cache();
if ($cache->check()) {
$template=$cache->read();
}else {
ob_start();
ob_implicit_flush(0);
?>
页面内容。。。。
<?php
$template = ob_get_contents();
$cache->write($template);
}
?>
ajax php教程仿网易文章评论顶一下效果
<div class='plding fr'>
<a href='action.php?id="1&action=top_num'>顶一下</a>[5]
</div>
js ajax
<script language="网页特效" type="text/javascript">
<!--
// ajax检测评论是否已经支持过了
function getcookie(c_name){ //检测cookie
if (document.cookie.length>0){
c_start=document.cookie.indexof(c_name + "=")
if(c_start!=-1){
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexof(";",c_start);
if(c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}function setcookie(c_name,value,expiredays){ //设置cookie
var exdate=new date();
exdate.setdate(exdate.getdate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.togmtstring());
}function createxmlhttprequest(){ //创建xmlhttprequest对象
if(window.activexobject){ //ie
try {
return new activexobject("microsoft.xmlhttp");
} catch(e){
return;
}
}else if(window.xmlhttprequest){ //mozilla,firefox
try {
return new xmlhttprequest();
} catch(e){
return;
}
}
}function get_top_num(id){ //主调函数
var get_top_cookie=getcookie('get_top_'+id+'_cookie');
if(get_top_cookie!=null && get_top_cookie!=""){
alert('此条评论你已经支持过了');
}
else{
var xmlhttp=createxmlhttprequest();
var url = "action.php?action=top_num&id="+id;
if (id==""){
return false ;
}
if (xmlhttp){
callback = getreadystatehandler(xmlhttp,id);
xmlhttp.onreadystatechange = callback;
xmlhttp.open("get", url,true);
xmlhttp.send(null);
}
setcookie('get_top_'+id+'_cookie','istop',1);
}
}function getreadystatehandler(xmlhttp,id){ //服务器返回后处理函数
var top_num = document.getelementbyid("top_num_"+id).innerhtml;
return function (){
if(xmlhttp.readystate == 4){
if(xmlhttp.status == 200){
if (xmlhttp.responsetext==1){
document.getelementbyid("top_num_"+id).innerhtml=number(top_num)+1;
}
}
}
}
}//-->
</script>
php教程 自动分页类函数
不想重复的写sql代码,就用下面的函数去自动处理了。
$__t_page_moyo_html = '';
/**
*
* 临时代码:分页处理函数
* @param string $sql
*/
function page_moyo($sql = '')
{
global $__t_page_moyo_html;
if ($sql == '')
{
return $__t_page_moyo_html;
}
// config
$max = 12;
$flag = 'page';
// step .1 处理sql语句
$sql_count = preg_replace('/select.*?from/is', 'select count(*) as mcnt from', $sql);
// step .2 获取数据量
$result = dbc()->query($sql_count)->getrow();
$total = $result['mcnt'];
// step .3 判断是否需要分页
if ($total < $max)
{
return $sql;
}
// step .4 获取当前页数
$pn = isset($_get[$flag]) ? (int)$_get[$flag] : 1;
if ($pn <= 0) $pn = 1;
// step .5 重组sql语句
$sql = $sql . ' limit '.($pn-1)*$max.','.$max;
// step .6 组装分页html代码
$url = $_server['request_uri'];
if (preg_match('/'.$flag.'=d+/i', $url))
{
$url = preg_replace('/[&]?'.$flag.'=d+/', '', $url);
}
$pageall = ceil($total/$max);
$pre = '';
if ($pn > 1)
{
$pre = ' / <a href="'.$url.'&'.$flag.'='.($pn-1).'">上一页</a>';
}
$nxt = ' / <a href="'.$url.'&'.$flag.'='.($pn+1).'">下一页</a>';
$html = '<a href="'.$url.'">首页</a>'.$pre.$nxt.' / <a href="'.$url.'&'.$flag.'='.$pageall.'">尾页</a>';
$__t_page_moyo_html = $html;
return $sql;
}
在进行sql查询前用page_moyo处理一下sql语句
$sql = page_moyo($sql);
然后在需要显示分页链接的地方直接调用page_moyo输出
echo page_moyo();
如果要连续进行两次大数据量sql查询的话就要在第一次查询后存储下当时的分页代码,不然下个sql查询就会覆盖掉了
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/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教程 在线切图程序代码
</title>
<style>
/* { -moz-box-sizing:border-box; } */body {
background-color:#aaa;
font-family:tahoma;
font-size:12px;
}
a {
text-decoration: none;
outline:none;
}
a:focus {
-moz-outline:none;
outline:none;
}#window {
background-color:threedface;
position:absolute;
width:850px;
height:500px;
left:10%;
top:10%;border:1px solid;
border-top-color:threedlightshadow;
border-left-color:threedlightshadow;
border-right-color:windowframe;
border-bottom-color:windowframe;z-index:2;
}#workspace {
background-color:#ece9d8; /*threedface*/
overflow:auto;position:absolute;
width:98%;
height:84%;
top:51px;
left:8px;
right:0;
bottom:74px;
z-index:3;border:1px solid;
border-top-color:threeddarkshadow;
border-left-color:threeddarkshadow;
border-right-color:threedhighlight;
border-bottom-color:threedhighlight;
}#myimg {
display:none;
position:absolute;
margin:3px;
}
#canvas, #canvastemp {
display:none;
position:absolute;
margin:3px;
background-color:transparent;
border:1px solid #666666;
/* background-image:url(back.gif); */
}
#shapes{
position:absolute;
margin:3px;
}#titlebar, #menubar, #statusbar, #resize {
background-color:threedface;
z-index:10;
position:absolute;
}#titlebar {
left:2px;
top:2px;
height:22px;
width:99.4%;
overflow:hidden;}
#gradient {
width:100%;
}
#menubar {
left:0px;
top:27px;
height:20px;
width:100%;
list-style:none;
margin:0;padding:0;
z-index:10;
border-bottom:1px solid threedshadow;
}#menubar li {
border:0px;
margin:0;
margin-top:1px;
font:menu;
float:left;
padding:1px;
padding-left:0.4em; padding-right:0.4em;
cursor:default;
}#statusbar {
z-index:6;
left:8px;
bottom:0;
height:26px;
width:98%;
border-top:1px solid threedhighlight;
padding-top:2px;
}#resize {
z-index:100;
bottom:0; right:0;
width:15px; height:15px;
background:transparent url('../resize.gif') 3px 3px no-repeat;
cursor:nw-resize;
}#titlebar canvas {
position:absolute;
width:100%;
}
#titlebar h1 {
background:transparent url('../cut.gif') 1px 2px no-repeat;
position:absolute;
color:captiontext;
font-size:12px;
margin:0;padding:0;
padding-left:20px;
padding-top:2px;
cursor:default;
}
#titlebar h2 {
position:absolute;
color:yellow;
font-size:12px;
margin:0;padding:0;
right:8px;
padding-top:2px;
cursor:default;
}
#statusbar2 {
margin-left:0px;
}#statusbar2 > div {
float:left;
}#statusbar2 #status { float:left; width:57%;}
#statusbar2 #xy { float:left; width:20%;}
#statusbar2 #txy { float:left; width:20%;}#status div, #xy div, #txy div {
padding:3px;
border:1px solid;
border-top-color:threedshadow;
border-left-color:threedshadow;
border-right-color:threedhighlight;
border-bottom-color:threedhighlight;
height:1.3em;
*height:1.7em;
line-height:1.3em;
overflow:hidden;
}
</style>
<script>
var mode = 1;
var inout = toubai = 0;
var img, imgurl = '', imgdata = '';
var p = '';
var xydir = 15;
var startangle=0, endangle=(math.pi/180)*270;
var m;
var win, wsp, canvas, c, canvastemp, ctemp, shapes;
var w,h,f;
var isshift = 0;
var shape = 0;
var theobject = null;
var dx, dy, dw, dh;
var des = '';
var iface = { dragging:false, resizing:false, status:null, xy:null, txy:null }
var anyt = 1;var isie = /msie/i.test(navigator.useragent);
var isff = /firefox/i.test(navigator.useragent);window.onload = function()
{
win = document.getelementbyid('window');
wsp = document.getelementbyid('workspace');img = document.getelementbyid('myimg');
canvas = document.getelementbyid('canvas');
canvastemp = document.getelementbyid("canvastemp");
shapes = document.getelementbyid('shapes');
rects = document.getelementbyid('rect');
win.style.left = document.body.clientwidth/2-425+'px';
if (canvas.getcontext)
{
c = canvas.getcontext("2d");
c.linewidth = 1;
c.strokestyle = '#f00';
c.fillstyle = "rgba(255,255,255,0.3)";
c.strokefill = 1;ctemp = canvastemp.getcontext("2d");
ctemp.linewidth = 1;
ctemp.strokestyle = '#f00';
ctemp.fillstyle = "rgba(255,255,255,0.3)";
ctemp.strokefill = 1;
var gradientcanvas = document.getelementbyid('gradient');
if (gradientcanvas.getcontext)
{
var g = gradientcanvas.getcontext('2d');
var grad = g.createlineargradient(0, 0, 1200, 22);
grad.addcolorstop(0, '#036');
grad.addcolorstop(1, '#acf');
g.fillstyle = grad;
g.fillrect(0, 0, 1200, 22);
}
iface.status = document.getelementbyid('status').firstchild;
iface.xy = document.getelementbyid('xy').firstchild;
iface.txy = document.getelementbyid('txy').firstchild;
document.onmouseup = window.onmouseup = bodyup;
document.onmousemove = window.onmousemove = bodymove;
document.onkeydown = window.onkeydown = keydown;
document.onkeyup = window.onkeyup = keyup;
img.onmousedown = canvas.onmousedown = canvastemp.onmousedown = shapes.onmousedown = c_down;
img.onmousemove = canvas.onmousemove = canvastemp.onmousemove = shapes.onmousemove = c_move;
img.onmouseup = canvas.onmouseup = canvastemp.onmouseup = shapes.onmouseup = c_up;
img.onmouseo教程ut = canvas.onmouseout = canvastemp.onmouseout = c_out;
}
else //不支持canvas属性
{
alert('不支持canvas');
}}
function openimg()
{
var form = document.upimg;var file = form.ifile.value;
var pos = file.lastindexof('.');
var ext = file.substring(pos + 1).tolowercase();
if (ext != 'jpg' && ext != 'gif' && ext != 'bmp' && ext != 'png')
{
alert('错误:上传图片必须是 jpg/gif/bmp/png 格式!');
return;
}
form.submit.click();
document.getelementbyid('upimg').style.display = 'none';
}function upimg(url, size, ww, hh, ff)
{
shape = 0;
des = '大小:'+size+' 字节 帧数:'+ff+' 帧 宽度:'+ww+' 像素 高度:'+hh+' 像素';
iface.status.innerhtml=des;
imgurl = url;
imgdata = 'imgurl='+imgurl+';';
if (ww>800) {w = 800; h = hh/(ww/800);}
else {w = ww; h= hh;}
f = ff;
//img.src = imgurl;
document.getelementbyid('myimg').style.display = 'block';
document.getelementbyid('myimg').src = imgurl;
canvas.style.display='block';
canvastemp.style.display='block';
canvas.width = canvastemp.width = w;
canvas.height = canvastemp.height = h;
canvas.style.width = canvastemp.style.width = w+'px';
canvas.style.height = canvastemp.style.height = h+'px';
c.clearrect(0, 0, canvas.width, canvas.height);
ctemp.clearrect(0, 0, canvastemp.width, canvastemp.height);
c.strokestyle = '#f00';
c.fillstyle = "rgba(255,255,255,0.3)";
ctemp.strokestyle = '#f00';
ctemp.fillstyle = "rgba(255,255,255,0.3)";
}function init(t)
{
if (imgurl == '') {alert('请先上传图片!');return;}
else alert("当前版本是演示版!");
}
function reset()
{
if (imgurl == '') {alert('请先上传图片!');return;}
else alert("当前版本是演示版!");
}
function clip()
{
if (imgurl == '') {alert('请先上传图片!');return;}
else alert("当前版本是演示版!");
}function hover(o)
{
o.style.border = "1px solid";
o.style.bordercolor = "threedhighlight threeddarkshadow threeddarkshadow threedhighlight";
}
function hoverout(o)
{
o.style.border = "0px solid transparent";
}function help()
{
document.getelementbyid('help').style.display='block';
}
function about()
{
document.getelementbyid('about').style.display='block';
}
function wrong(str)
{
alert(str);
}
</script>
<!--[if ie]>
<script type="text/网页特效" src="js/excanvas.js"></script>
<![endif]-->
</head><body id="body">
<form name="build" enctype="multipart/form-data"><input type="hidden" name="imgdata"><input type="hidden" name="region"><input type="hidden" name="back"><input type=submit name=submit style="position:absolute;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;");></form><div id="window">
<div id="titlebar" onmousedown="windowdrag(event)" oncontextmenu="return false"><canvas id="gradient" height="22"></canvas><h1 style="margin-top:2px;">图片裁剪工具</h1><h2 style="margin-top:1px;"><a href="javascript:help();" hidefocus="true"><font color=yellow>操作说明</font></a> <a href="javascript:about();" hidefocus="true"><font color=yellow>关于我们</font></a></h2>
</div>
<ul id="menubar" oncontextmenu="return false">
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="document.getelementbyid('help').style.display='none';document.getelementbyid('about').style.display='none';document.getelementbyid('set').style.display='none';document.getelementbyid('upimg').style.display='block';"> 上传图片(<u>u</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(1);">矩形裁剪(<u>r</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(2)">圆形裁剪(<u>o</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(3)">圆角矩形裁剪(<u>c</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(4)">圆弧裁剪(<u>a</u>)</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(5)">多边形裁剪</li>
<li style="top:0px;margin-left:-3px;padding-left:0px;margin-top:-2px;padding-top:0px;padding-bottom:0px;"><input type="radio" name="any" id="line" hidefocus disabled checked>直边<input type="radio" name="any" id="curve" hidefocus disabled>曲边</li>
<li onmouseover="hover(this)" onmouseout="hoverout(this)" onclick="init(6)">任意图形裁剪(<u>m</u>)</li>
<li style="margin-top:0px;margin-right:7px;*margin-right:5px;float:right;padding-top:1px;*padding-top:2px;padding-bottom:1px;*padding-bottom:0px;border:1px solid threeddarkshadow;color:red" onclick="clip()">裁剪</li>
<li style="margin-top:0px;margin-right:7px;*margin-right:5px;float:right;padding-top:1px;*padding-top:2px;padding-bottom:1px;*padding-bottom:0px;border:1px solid threeddarkshadow;color:red" onclick="reset()">重置</li>
<li style="margin-top:0px;margin-right:7px;*margin-right:5px;float:right;padding-top:1px;*padding-top:2px;padding-bottom:1px;*padding-bottom:0px;border:1px solid threeddarkshadow;color:red" onclick="document.getelementbyid('set').style.display='block'">设置</li>
</ul>
<div id="workspace" oncontextmenu="return false">
<img id="myimg">
<canvas id="canvas" oncontextmenu="return false"></canvas>
<canvas id="canvastemp" oncontextmenu="return false"></canvas>
<div id="shapes">
<table class=resizeme id=rect style="position:absolute;z-index:100;border:0px dotted #ff0000;width:100;height:100;display:none;" cellspacing="0" cellpadding="0"><tr><td></td></tr></table>
</div>
</div><div id="statusbar" oncontextmenu="return false"><div id="statusbar2">
<div id="status"><div> </div></div>
<div id="xy"><div> </div></div>
<div id="txy"><div> </div></div>
</div></div>
<div id="resize" onmousedown="windowresize(event, this)" oncontextmenu="return false"></div><form id="upimg" name="upimg" action="upload.php" method="post" enctype="multipart/form-data" target="_frame" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-163px;*margin-left:-175px;margin-top:-80px;width:325px;*width:350px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:none">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 上传图片</b></div>
<div style="background-color:threedface;padding-top:6px;padding-bottom:6px;padding-left:10px;"><input size="24" type="file" name="ifile" onchange="openimg();" style="height:22px"> <input type="button" value=" 取 消 " style="height:22px" onclick="document.getelementbyid('upimg').style.display='none'"><input type=submit name=submit style="position:absolute;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;"></div>
</form>
<form id="set" name="set" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-125px;margin-top:-80px;width:250px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:none">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 设置</b></div>
<div><div style="background-color:threedface;padding-top:6px;padding-bottom:6px;padding-left:24px">裁剪方向:<input type="radio" name=inout id=isin hidefocus checked>裁剪内部 <input type="radio" name=inout id=isout hidefocus>裁剪外部<p style="margin-top:3px;margin-bottom:3px">背景颜色:<input type="radio" name=toubai id=istou value=0 hidefocus checked>透明背景 <input type="radio" name=toubai id=isbai value=1 hidefocus>白色背景</div><div style="background-color:threedface;padding-bottom:8px;"><center><input type="button" value=" 确 定 " style="height:22px" onclick="setting()"> <input type="button" value=" 取 消 " style="height:22px" onclick="document.getelementbyid('set').style.display='none'"></center></div></div>
</form>
<div id="help" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-210px;margin-top:-170px;width:420px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:block">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 操作说明</b></div>
<div><div style="background-color:threedface;padding-top:6px;padding-bottom:6px;padding-left:10px;padding-right:10px"><center><font color=red>【鼠标操作说明】</font></center><p style="margin-top:6px;margin-bottom:6px">[1] 鼠标拖动裁剪框可移动裁剪区域的位置,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:4px;margin-bottom:4px">[2] 鼠标拉拽裁剪框边框可调整裁剪区域的大小,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【键盘操作说明】</font></center><p style="margin-top:6px;margin-bottom:6px">[3] 按←↑↓→键可精确移动裁剪区域的位置,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:4px;margin-bottom:4px">[4] 按jklm键可精确调整裁剪区域的大小,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪,圆弧裁剪。<p style="margin-top:4px;margin-bottom:4px">[5] 按a键减小圆角矩形的圆角角度,按d键增大圆角矩形的圆角角度,此操作适用于圆角矩形裁剪。<p style="margin-top:4px;margin-bottom:4px">[6] 按awsd键可调整圆弧的弧度,此操作适用于圆弧裁剪。<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【shift操作说明】</font></center><p style="margin-top:6px;margin-bottom:6px">[7] 拉拽鼠标的同时按shift键可按宽与高1:1的比例调整裁剪区域的大小,此操作适用于矩形裁剪,圆形裁剪,圆角矩形裁剪。</div><div style="background-color:threedface;padding-bottom:8px;"><center><input type="button" value=" 关 闭 " style="height:22px" onclick="document.getelementbyid('help').style.display='none'"></center></div></div>
</div>
<div id="about" style="position:absolute;background-color:#036;left:50%;top:50%;margin-left:-190px;margin-top:-120px;width:380px;padding-top:3px;padding-left:3px;padding-bottom:3px;padding-right:3px;z-index:12;display:none">
<div style="background-color:#036;padding-top:1px;padding-left:2px;color:captiontext;font-size:12px;height:20px"><b> 关于我们</b></div>
<div><div style="background-color:threedface;padding-top:8px;padding-bottom:6px;padding-left:10px"><center><font color=red>【本站宗旨】</font></center><p style="margin-top:6px;margin-bottom:6px">● 本站旨在为广大网民提供最专业最全面的图片裁剪服务.<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【站点说明】</font></center><p style="margin-top:6px;margin-bottom:6px">● 本站提供以下服务:图片裁剪,照片裁剪,矩形裁剪,圆形裁剪,弧形裁剪,多边形裁剪,任意图形裁剪,动态图片裁剪.<p style="margin-top:8px;margin-bottom:8px"><center><font color=red>【联系我们】</font></center><p style="margin-top:6px;margin-bottom:6px">● 对本站如有疑问之处请与我们联系:service@caijian.cc.</div><div style="background-color:threedface;padding-bottom:8px;"><center><input type="button" value=" 关 闭 " style="height:22px" onclick="document.getelementbyid('about').style.display='none'"></center></div></div>
</div>
<div style="display:none;">
<iframe id="_frame" name="_frame"></iframe>
</div>
</div>
</body>
</html>upload.php文件
<?php
if (stripos($_server[ "http_host"], 'caijian.cc') === false) exit(0);
if ((($_files["ifile"]["type"] == "image/gif")
|| ($_files["ifile"]["type"] == "image/jpeg")
|| ($_files["ifile"]["type"] == "image/pjpeg")
|| ($_files["ifile"]["type"] == "image/bmp")
|| ($_files["ifile"]["type"] == "image/png"))
&& ($_files["ifile"]["size"] < 3000000))
{
if ($_files["ifile"]["error"] > 0)
{
echo "<script language='javascript'>" ;
echo "parent.wrong('上传图片出错,请重新上传!');";
echo "</script>";
}
else
{
$filename = "upload/".date("ymdhis",time()).rand(100,999).substr($_files["ifile"]["name"],strrpos($_files["ifile"]["name"],'.'));
move_uploaded_file($_files["ifile"]["tmp_name"], $filename);
$magick_wand = newmagickwand();
magickreadimage($magick_wand, $filename);
$w = magickgetimagewidth($magick_wand);
$h = magickgetimageheight($magick_wand);
$f = magickgetnumberimages($magick_wand);
echo "<script language='javascript'>" ;
echo "parent.upimg('".$filename."',".$_files["ifile"]["size"].", $w, $h, $f);";
echo "</script>";
}
}
else
{
echo "<script language='javascript'>" ;
echo "parent.wrong('上传照片尺寸不得大于3m!');";
echo "</script>";
}
?>
源码下载地址
http://down.111cn.net/php/2011/0311/22879.html
相关文章
- 专做了百度和google的网盟推广以作推广效果的评估比较。百度的周期为6天,google为4天。 从百度的统计数据可以看出这六天的点击次数总共为464,平均点击花费了0.30元...2017-07-06
- 这篇文章主要介绍了C# 中的var关键字详细介绍的相关资料,需要的朋友可以参考下...2020-06-25
- yield这个关键字是和迭代器挂钩的,而且是与return一起以yield return的形式合用的,用来返回迭代器中的条目。...2020-06-25
基于JavaScript实现高德地图和百度地图提取行政区边界经纬度坐标
本文给大家介绍javascript实现高德地图和百度地图提取行政区边界经纬度坐标的相关知识,本文实用性非常高,代码简单易懂,需要的朋友参考下吧...2016-01-24如何根据百度地图计算出两地之间的驾驶距离(两种语言js和C#)
以下是使用js代码实现百度地图计算两地距离,代码如下所示:<script src="js/jquery-1.9.0.js" type="text/javascript" language="javascript"></script><script language="javascript" type="text/javascript" src="js/...2015-10-30- 百度联盟封号对于许多的站长来说肯定是会影响到心情的,那么既然是百度联盟封号了我们就肯定有一些原因的,虽然不是你自己搞的或一些其它因素都有可能,我们下面整理一下百...2016-10-10
Spring Data JPA 关键字Exists的用法说明
这篇文章主要介绍了Spring Data JPA 关键字Exists的用法说明,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-06-10- 网站被K后,笔者做的第一件事便是在网站上增加更新模块。百度算法更新,对于网站内容给予了相当大的权重,这是笔者网站最欠缺的部分,保证了及时的更新便有了吸引蜘蛛爬取的...2016-10-10
- 对于批量替换关键字的问题,仅替换而言没什么可说的,但这里需要的是每个关键字仅需要替换一次就可以了。查阅了php相关函数文档,发现php本身是没有函数实现这个功能的,所以不得不自己解决了。总结了几种可行方法,小记一下! (1...2015-10-30
- 这篇文章主要介绍了c# volatile 关键字的相关资料,帮助大家更好的理解和学习c#的相关知识,感兴趣的朋友可以了解下...2020-12-08
- 我们知道百度熊抱枕很大,只想要百度熊的大头,该怎么办呢?下面我们就来看看详细的教程。 1、首先打开photoshopCS6软件,新建一个“1600*1600”的白色背景图,并从右上角...2016-12-31
- 这篇文章主要介绍了如何用python获取txt文件中关键字的数量,帮助大家更好的理解和使用python,感兴趣的朋友可以了解下...2020-12-24
如何根据百度地图计算出两地之间的驾驶距离(两种语言js和C#)
以下是使用js代码实现百度地图计算两地距离,代码如下所示:<script src="js/jquery-1.9.0.js" type="text/javascript" language="javascript"></script><script language="javascript" type="text/javascript" src="js/...2015-10-30- 网页头部head 部分:TITLE 、<mtea>部分 网站描述Description、keyword 内容中的关键词,大家优化时也都比较重视这部分的关键词优化,因为在查询搜索结果时此处出现的关键词...2017-07-06
- 用户为满足自己某种需求而来到搜索引擎的,判断用户的需求是做好网站的开始。只有准确地判断出用户需求,了解用户搜索的目的,才能合理地衡量出一个网站结果的质量好,做好搜...2016-10-10
- 这篇文章主要介绍了Delphi常用关键字用法,包括了各个常用的关键字及其详细用法,需要的朋友可以参考下...2020-06-30
- 这篇文章主要介绍了Java类的访问权限关键字用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-29
- 这篇文章主要对C语言中const关键字的用法进行了详细的分析介绍,需要的朋友可以参考下...2020-04-25
JS实现获取来自百度,Google,soso,sogou关键词的方法
这篇文章主要介绍了JS实现获取来自百度,Google,soso,sogou关键词的方法,结合实例形式分析了js获取来路页面的方法与相关搜索引擎关键词的处理技巧,需要的朋友可以参考下...2017-01-09- 这篇文章主要给大家介绍了关于Swift中static和class关键字的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者使用Java具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧...2020-06-30