您的位置:首页 > 运维架构 > 网站架构

让你的网站/app拥有自己的淘宝内部优惠券广告系统(php)

2017-01-02 23:50 239 查看
特色说明:

适合拥有自己内容(网站\app等)和人气资源的广大站长朋友们!
兼容性:兼容windows/linux系统;上传数据支持gb2312/utf-8编码。
易操作:基本上转好数据上传即可;数据转化方便。
自适应:自动页面宽度;少于320就显示320PX;大于568就显示568px
特别适合手机通栏广告。
速度快:直接另存的1万条9MB多的淘宝优惠券.dat文件,速度0.03秒。
操作说明:
前台访问:http://网址/目录/index.php (上传到PHP空间直接运行)
后台访问:无需后台(无后台)
数据转化:见后边的步骤
数据操作:通过FTP管理(转好数据上传替换taobao.dat文件)
显示个数修改:建议用notepad等代码编辑器打开编辑index.php 内的参数。
数据转化(淘宝优惠券)
一般只需以下1、3、4三步即可。
1.每天上午10点下载淘宝联盟的优惠券表格。
2. 速度已经很快,以下2.1 2.2选做,因为对速度提升并不明显。
2.1 如果有不想显示的列删除列,可以减少数据大小、加快显示速度。
2.2 如果有不想显示的行可以先删除,可以减少数据大小、加快显示速度。
3.另存为制表符分开的txt文件,然后更名为taobao修改后缀为(.dat)。
4.将该数据用你常用的上传手段上传至网站目录下(与.php文件同级)。
网站调用(iframe方式)
1. 用iframe方式调用。以下仅为参考。

1. index.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=gb2312" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>我是淘宝优惠券-youhui.17386.net</title>
<meta name="author" content="yujianyue, admin@ewuyi.net">
<meta name="copyright" content="youhui.17386.net">
<!--Powered By youhui.17386.net-->
<head>
<body>
<style type="text/css">
/*结果*/
*{FONT-SIZE:14px;margin:0 auto;font-family:"microsoft yahei";line-height:150%;}
a{color:blue;text-decoration:none;}
s{color:#999999;}
b{color:red;}
a:hover {color:green;}
table{border-top:0px solid #0180CF; margin:0 auto;width:95%;max-width:568px;}
table td{padding:3px;word-wrap:break-word;word-break:break-all;min-width:80px;max-width:300px;}
.tt{background:#e5f2fa;line-height:18px;FONT-SIZE:18px;}
.tup{text-align:center;vertical-align:center;width:100px;height:100px;}
.img{width:96%;min-width:88px;max-width:128px;}
.tim{font-family:"Microsoft JhengHei";}
.jia{height:28px;color:red;}
.but{width:68px;}
</style>

<?php
function characet($data){
if(!empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != 'UTF-8'){
$data = mb_convert_encoding($data ,'UTF-8' , $fileType);
}
}
return $data;
}

function get_file_line($file_name, $line){
$n = 0;
$handle = fopen($file_name,'r');
if ($handle) {
while (!feof($handle)){
++$n;
$out = fgets($handle, 4096);
if($n==$line) break;
}
fclose($handle);
}
if($line==$n) return $out;
return false;
}

$moban01="<table class='tbyouhui'>"
. "<tbody>"
. " <tr>"
. " <td rowspan=\"2\" class='tup' ><a href='<!--商品主图-->' target='_blank'>\r\n"
. " <img src='<!--商品主图-->' class='img' align='absmiddle'></a></td>\r\n"
. " <td colspan=\"2\" class='tim' style=\"text-align:left;vertical-align:top;\">\r\n"
. " <a href='<!--淘宝客链接-->' target='_blank'><!--商品名称--></a></td>\r\n"
. " </tr>\r\n"
. " <tr>\r\n"
. " <td class='jia'><s> <!--商品价格(单位:元)--> </s><br><!--优惠券面额--></td>\r\n"
. " <td class='but'><a href='<!--商品优惠券推广链接-->' target='_blank'>先领优惠券</a></td>\r\n"
. " </tr>\r\n"
. "</tbody>\r\n"
. "</table>\r\n\r\n";

//error_reporting(0);
$stime=microtime(true);

$linet = "3"; //随机显示的宝贝数量/条数推荐:1-10
$files = "taobao.dat"; //数据库名称:数字字母组成:文本内容可以是编码gb2312/utf-8

if(!file_exists($files)){
$files = "taobao.dat"; //默认备用数据库:同级taobao.dat
echo "<!-- Powered By youhui.17386.net 文件 $files 不存在 -->\r\n";
}else{
$a=file($files);//把文件的所有内容获取到数组里面
$n=count($a);//获得总行数
echo "<!-- Powered By youhui.17386.net 文件: $files $n 条记录 -->\r\n";
$rnd_tite = trim(characet(get_file_line($files, "1")));//读取列标题
$rnd_tito=explode("\t",$rnd_tite);
for($line=0; $line<$linet; $line++) {
$lines = rand(2, $n-1); //随机读取栏目
echo "<!-- Powered By youhui.17386.net 第 $lines 条记录 -->\r\n";
$rnd_ones = characet(get_file_line($files, $lines));
$rnd_ones = trim($rnd_ones);
$tab_one=explode("\t",$rnd_ones);
$iit = -1;
$html_ones = $moban01;
foreach($tab_one as $tabu){
$iit++;
$taba=$rnd_tito[$iit];
$html_ones = str_replace("<!--$taba-->",$tabu,$html_ones);
}
echo $html_ones;
}
}
$etime=microtime(true);//获取程序执行结束的时间
$total=$etime-$stime; //计算差值
echo "<!--页面执行时间:{$total} ]秒-->";
?>
</body>
</html>

2. taobao.dat
根据上边:数据转化(淘宝优惠券)1、3、4三步转化后和index.php放一起。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: