Skip to content

Instantly share code, notes, and snippets.

@zsmynl
zsmynl / gist:7818706
Created December 6, 2013 04:43
判断指定的标签是否被选,如果选了弹出询问框;
if($("#neglect").is(':checked')){
if(confirm("确定忽略此漏洞吗?")){
return true;
}else{
return false;
}
}
@zsmynl
zsmynl / preg.php
Created January 20, 2014 09:58
过滤掉以“/开头”和“结束/”之间的字符串;
<?php
$str = '哈哈,开头我是被过滤的垃圾内容结束我才是要显示的内容一,开头我是被过滤的垃圾内容结束我才是要显示的内容二';
echo $str = preg_replace("/开头.*?结束/", '', $str);
?>
@zsmynl
zsmynl / Filter.php
Created January 20, 2014 10:07
一次回复评论的简单过滤总结;php过滤;preg_replace();过滤关键词,过滤邮箱,过滤链接,过滤QQ,手机号;
<?php
$comment=get_var("comment","POST");
if(!empty($comment)){
/* 回复过滤 @zm 2014-1-12 Begin */
$commentFilter['0']='神马';
$commentFilter['1']='浮云';
$commentFilter['2']='QQ';
$commentFilter['3']='qq';
$commentFilter['4']='扣扣';
$commentFilter['5']='秋秋';
@zsmynl
zsmynl / wrap.php
Created January 20, 2014 10:26
php过滤换行符的方法;
<?php
//php 不同系统的换行
//不同系统之间换行的实现是不一样的
//linux 与unix中用 /n
//MAC 用 /r
//window 为了体现与linux不同 则是 /r/n
//所以在不同平台上 实现方法就不一样
//php 有三种方法来解决
//1、使用str_replace 来替换换行
@zsmynl
zsmynl / test.php
Created February 6, 2014 20:25
调试服务器环境常用测试
<?php
error_reporting(E_ALL);
$con=mysql_connect('localhost','root','')or die('数据库连接失败');
$db=mysql_select_db('test',$con);
$sql="SELECT name FROM user";
$query=mysql_query($sql,$con);
while ($row=mysql_fetch_assoc($query)) {
$list[]=$row;
}
foreach ($list as $k => $v) {
@zsmynl
zsmynl / curl_post.php
Created February 7, 2014 21:50
php使用curl进行post数据;
<?php
function request($url,$data='',$headers=array()) {
if(empty($headers['UserAgent'])) $headers['UserAgent']='Mozilla/5.0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
if($data){
curl_setopt($ch, CURLOPT_POST, 1);
@zsmynl
zsmynl / localStorage.js
Created February 10, 2014 08:39
使用localStorage保存页面内容。
/* 保存填写内容 begin */
<script type="text/javascript">
function saveMyContent(){
if(window.localStorage){
var items=["bugtitle","description","editor_content","editor_content1","editor_content2","usertags"];
$.each(items,function(k,v){
var inputValue=$("#"+v).val();
if (inputValue==null ||inputValue==""){
inputValue="";
}else{
@zsmynl
zsmynl / randomkeys.php
Created February 14, 2014 03:50
php简单的声称随机字符串/
<?php
/* 生成随机字母与数字混合验证码 */
function randomkeys($length) {
$returnStr='';
$pattern='23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ';
for($i=0;$i<$length;$i ++) {
$returnStr.=$pattern{mt_rand(0,strlen($pattern)-1)}; //生成php随机数
}
return $returnStr;
}
@zsmynl
zsmynl / .htaccess
Created February 22, 2014 11:22
记一次htaccess伪静态
RewriteEngine on
RewriteRule ^discover$ index.php?do=discover
RewriteRule ^content/([a-zA-Z0-9_-]+)$ index.php?do=content&workid=$1
RewriteRule ^discover/([a-zA-Z0-9_-]+)$ index.php?do=discover&id=$1
RewriteRule ^content/([a-zA-Z0-9_-]+)/id/([a-zA-Z0-9_-]+)$ index.php?do=content&workid=$1&contentId=$2
RewriteRule ^home/([a-zA-Z0-9_-]+)$ index.php?do=home&id=$1
RewriteRule ^works/([a-zA-Z0-9_-]+)$ index.php?do=home&act=works&id=$1
@zsmynl
zsmynl / localimg.php
Created February 24, 2014 09:53
php图片采集后按原路径保存图片
<?php
$domain ='http://www.xxxx.com';
$url = '/newskin/images/v4/logo.jpg';
$pats = pathinfo($url);
$dir = '.'.$pats['dirname'].'/';
if(!is_dir($dir))
{
@mkdirs($dir, 0777);
@fclose(fopen($dir.'/index.htm', 'w'));
}