传入Base64字符串,获取生成图片的字节大小

function checkpic(str){

str=str.substring(22);
var equalIndex= str.indexOf(‘=’);
if(str.indexOf(‘=’)>0)
{
str=str.substring(0, equalIndex);

}

var strLength=str.length;
var fileLength=parseInt(strLength-(strLength/8)*2);
if((fileLength/1024)>=2048){
return false;
}else{
return true;
}
}

PHP 合并两张图 , 一张是框 , 一张是内容图 , 生成png背景透明的合并图

<?php
/**
* 拼接图片
* $photo:边框内的图片绝对路径:win:E:\xamp\htdocs\news\images/pic.png
*                           linux:/usr/local/apache/htdocs/site/images/pic.png
* $kuang:边框路径:与$photo格式相同
*/
function spliceImage($photo,$kuang){
//将两幅图分别取到两个画布中
$image_kuang = imagecreatefrompng($kuang);
$image_photo = imagecreatefromjpeg($photo);
//创建一个新的,和大图一样大的画布
$image_3     = imageCreatetruecolor(imagesx($image_kuang),imagesy($image_kuang));
//为真彩色画布创建白色背景,再设置为透明
$color = imagecolorallocate($image_3, 255, 255, 255);
imagefill($image_3, 0, 0, $color);
imageColorTransparent($image_3, $color);
/**
* 制作水印的方法
* 先copy框再copy图片 这就添加水印的方法,先复制大图,再复制小图,小图覆盖大图
imagecopyresampled($image_3,$image_kuang,0,0,0,0,imagesx($image_kuang),imagesy($image_kuang),imagesx($image_kuang),imagesy($image_kuang));
imagecopymerge($image_3,$image_photo, 21,77,0,0,imagesx($image_photo),imagesy($image_photo), 100);
**/

/**
* 先copy图片,再copy画框,实现png的透明效果,将图片嵌入到画框里
*  imagecopymerge与imagecopy的不同:
*  imagecopymerge 函数可以支持两个图像叠加时,设置叠加层的透明度。imagecopymerge比imagecopy多一个参数,来设置透明度
*                  PHP内部源码里,imagecopymerge在透明度参数为100时,直接调用imagecopy函数。
*  imagecopy 函数则不支持叠加透明,但拷贝时可以保留png图像的原透明信息,而imagecopymerge却不支持图片的本身的透明拷贝
*  即:使用imagecopymerge函数,可以实现打上透明度为30%的淡淡的水印图标,但图片本身的png就会变得像IE6不支持png透明那样,背景不透明了。
*  如果使用imagecopy函数,可以保留图片本身的透明信息,但无法实现30%的淡淡水印叠加,
*/
imagecopyresampled($image_3,$image_photo,12,12,0,0,imagesx($image_photo),imagesy($image_photo),imagesx($image_photo),imagesy($image_photo));
//imagecopymerge($image_3,$image_kuang, 0,0,0,0,imagesx($image_kuang),imagesy($image_kuang), 70);
imagecopy($image_3,$image_kuang, 0,0,0,0,imagesx($image_kuang),imagesy($image_kuang));
//获得要保存的文件名
$photoArray =   explode(‘/’,$photo);
$fileName   =   explode(‘.’,end($photoArray));
$fileName   =   $fileName[0].’_n.png’;
//将图片保存为png格式
//存储图片路径
$newImage   =   “images/”.$fileName;
imagepng($image_3, $newImage);
//返回图片路径
$imageUrl   =   “images/”.$fileName;
return $imageUrl;
}

$ttt = spliceImage(‘images/222.jpg’,’images/222.png’);
echo $ttt;
echo ‘<img src=”images/222_n.png”/>’;
echo ‘<style>body{background:gray;}</style>’;
?>

js 获取video视频的总秒数

<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<title>无标题文档</title>
</head>

<body>
<p>
<video src=”http://gslb.miaopai.com/stream/dmE59PRU2S4sVT9w50g2EQ__.mp4?ssig=a480a889802b89973127282b28a18804&time_stamp=1513336482828&cookie_id=&vend=1&os=3&partner=1&platform=2&cookie_id=&refer=miaopai&scid=dmE59PRU2S4sVT9w50g2EQ__” controls preload=”auto” id=”player”></video>
</p>
<input name=”submit” type=”submit” onclick=”getInfo()”>
<p>

<script language=”javascript”>
var time;
function getInfo(){
var pl=document.getElementById(“player”);
time = pl.duration;
alert(time);
}
</script>
</p>
</body>
</html>

PHP curl抓取网页,xpath匹配内容

$url = ‘http://www.baidu.com’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, fopen(‘php://stdout’, ‘w’));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);

// create document object model
$dom = new DOMDocument();
// load html into document object model
@$dom->loadHTML($html);
// create domxpath instance
$xPath = new DOMXPath($dom);
// get all elements with a particular id and then loop through and print the href attribute
$elements = $xPath->query(‘//*[@id=”lg”]/img/@src’);
foreach ($elements as $e) {
echo ($e->nodeValue);
}

demo2:

//http://www.php.net/manual/en/book.dom.php
$config = array(
    'name' => "neirong",
    'selector' => "//*[@id=\"post\"]/div[2]",
    'required' => true,
);

$url = "http://news.ci123.com/article/106582.html";

$html_string = file_get_contents($url);
$document = new DOMDocument(1.0);
$document->loadHTML($html_string);

$xpath = new DOMXPath($document);
$nodeList = $xpath->query($config['selector']);

foreach ($nodeList as $index => $node){
    echo $node->textContent; //不包含HTML标签
    echo "<br/>";
    echo $node->ownerDocument->saveHTML($node); //包含HTML标签
}
//xpath 匹配table标签是不加tbody..
错误:*[@id='content']/table[2]/tbody/tr/td/div
正确用法://*[@id='content']/table[2]/tr/td/div

php抓取网页特定div区块及图片

1. 取得指定网页內的所有图片:
<?php
取得指定位址的內容,並储存至text
$text=file_get_contents(‘http://www.baidu.com/’);
取得第一個img标签,並储存至阵列match(regex语法与上述同义)
preg_match(‘/<img[^>]*>/Ui’, $text, $match);
印出match
print_r($match);
—————–
2. 取得指定网页內的第一张图片:
<?php
取得指定位址的內容,並储存至text
$text=file_get_contents(‘http://www.baidu.com/‘);
取得第一個img标签,並储存至阵列match(regex语法与上述同义)
preg_match(‘/<img[^>]*>/Ui’, $text, $match);
印出match
print_r($match);
————————————
3. 取得指定网页內的特定div区块(藉由id判断):
<?php
取得指定位址的內容,並储存至text
$text=file_get_contents(‘http://www.baidu.com/’);
去除換行及空白字元(序列化內容才需使用)
$text=str_replace(array(“\r”,”\n”,”\t”,”\s”), ”, $text); 
取出div标签且id為PostContent的內容,並储存至阵列match
preg_match(‘/<div[^>]*id=”PostContent”[^>]*>(.*?) <\/div>/si’,$text,$match);
印出match[0]
print($match[0]);
——————————————-
4. 上述2及3的结合:
<?php
取得指定位址的內容,並储存至text
$text=file_get_contents(‘http://www.baidu.com/’); 
取出div标签且id為PostContent的內容,並储存至阵列match
preg_match(‘/<div[^>]*id=”PostContent”[^>]*>(.*?) <\/div>/si’,$text,$match); 
取得第一個img标签,並储存至阵列match2
preg_match(‘/<img[^>]*>/Ui’, $match[0], $match2);
印出match2[0]
print_r($match2[0]);

js实现支付密码效果,自动获取下一个input焦点

代码

window.onload = function() {
var txts = wrap.getElementsByTagName(“input”);
for(var i = 0; i < txts.length; i++) {
var t = txts[i];
t.index = i;
t.setAttribute(“readonly”, true);
t.onkeyup = function(event) {
if(event.keyCode == 8) {
this.value = this.value.replace(/^(.).*$/, ‘$1’);
var next = this.index – 1;
if(next > txts.length – 1) return;
txts[next].removeAttribute(“readonly”);
txts[next].focus();
return;
}
this.value = this.value.replace(/^(.).*$/, ‘$1’);
var next = this.index + 1;
if(next > txts.length – 1) return;
txts[next].removeAttribute(“readonly”);
txts[next].focus();
}
}
txts[0].removeAttribute(“readonly”);
}

使用js判断html滚动条到页面最底部代码

<script>

window.onscroll = function () {
//监听事件内容
if(getDocumentHeight() == getWindowHeight() + getScrollTop()){
//当滚动条到底时,这里是触发内容
//异步请求数据,局部刷新dom
alert(“已经到底了!”);
}
}
//滚动条总高度
function getDocumentHeight() {
var DocumentHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
if (document.body) {
bodyScrollHeight = document.body.scrollHeight;
}
if (document.documentElement) {
documentScrollHeight = document.documentElement.scrollHeight;
}
DocumentHeight = (bodyScrollHeight – documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
return DocumentHeight;
}

//可视窗口高度
function getWindowHeight() {
var windowHeight = 0;
if (document.compatMode == “CSS1Compat”) {
windowHeight = document.documentElement.clientHeight;
} else {
windowHeight = document.body.clientHeight;
}
return windowHeight;
}

//滚动条滚动高度
function getScrollTop() {
var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
if (document.body) {
bodyScrollTop = document.body.scrollTop;
}
if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop – documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
return scrollTop;
}

</script>