马 超
空洞的世界 · 共 20 篇文章
最全的常用正则表达式大全
很多不太懂正则的朋友,在遇到需要用正则校验数据时,往往是在网上去找很久,结果找来的还是不很符合要求。所以我最近把开发中常用的一些正则表达式整理了一下,包括校验数字、字符、一些特殊的需求等等。给自己留个底,也给朋友们做个参考。 一、校验数字的表达式 数字:^ $ n位的数字:^\d{n}$ 至少n位的数字:^\d{n,}$ m-n位的数字:^\d{m,n}$ 零和非零开头的数字:^(0| )$ 非零开头的最多带两位小数的数字:^( )+(.{1,2})?$ 带1-2位小数的正数或负数:^(-)?\d+(.\d{1,2})?$ 正数、负数、和小数:^(-|+)?\d+(.\d+)?$ 有两位小数…
2017-02-19T18:34:07Z · 编程语言 · 评论(0)
二维数组按照指定键值排序
$array = array( array('name'=>'手机','brand'=>'诺基亚','price'=>1050), array('name'=>'笔记本电脑','brand'=>'lenovo','price'=>4300), array('name'=>'剃须刀','brand'=>'飞利浦','price'=>3100), array('name'=>'跑步机','brand'=>'三和松石','price'=>4900), array('name'=>'手表','brand'=>'卡西欧','price'=>960), array('name'=>'液晶电视','bra…
2015-08-11T10:55:12Z · 编程语言 · 评论(0)
PHP计算当前时间之后(之前)的时间
PHP中有一个非常厉害的函数,strtotime()函数,这个函数有一个异常厉害的使用方法,手册上说的有,但是估计在实际应用中能够想到的人不多: 请看下面的列子: 当前时间之后的时间是“+”,之前的时间当然用“-”就可以了! strtotime(”+1 week”) 当前时间一周之后 strtotime(”-1 week”) 当前时间一周之前 strtotime(”+1 months”) 一个月之后 strtotime(”+5 days”) 5天之后 strtotime(”+12 hours”) 12个小时之后 strtotime(”+20 minutes”) 20分钟之后 strtotim…
2015-05-05T17:31:21Z · 编程语言 · 评论(0)
好用的图片缩略图上传类
<?php function resizeImage($im,$maxwidth,$maxheight,$name,$filetype) { $pic_width = imagesx($im); $pic_height = imagesy($im); if(($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight)) { if($maxwidth && $pic_width>$maxwidth) { $widthratio = $maxwidth/$pic_width; $resizewi…
2015-04-25T17:36:34Z · 编程语言 · 评论(0)
jQuery使用on()绑定动态生成元素的事件无效的问题
jQuery的on()方法可以绑定动态生成元素的事件,但是在实际使用时发现无效。如下HTML: <p> <a>123</a> </p> 使用如下方式,对静态元素有效,但是绑定动态生成的a元素的事件时无效: $('a').on('mouseenter', function(){ ............ }); 需要绑定a的父级元素(此元素必须为静态元素,不是后来动态生成的),然后设定on()方法的selector参数才行: $('p').on('mouseenter', 'a', function(){ .............. }); 这样才是正确的
2015-01-21T14:13:56Z · 编程语言 · 评论(0)
php模拟post提交
$post_data = array(); //普通值 $post_data['t'] = time(); $post_data['t1'] =123; //传递json数组 $post_data_json['baseid'] = "1210"; $post_data_json['email'] = "18651kMdvsjWCOb@mfsa.ru"; $post_data_json['answer'] = "704xklV5"; $post_data_json['platform'] = "ps"; $post_data_json['ignoretf'] = "1"; $post_data…
2015-01-09T14:43:03Z · 编程语言 · 评论(0)
jquery遍历数组与筛选数组的方法
在jquery是遍历筛选数组有多种方法与函数了,包括有:grep、each、inArray、map同时也要以遍历json对象哦,下面给各位同学介绍一下具体的操作方法: grep grep()方法用于数组元素过滤筛选 grep(array,callback,invert) array:待过滤数组; callback:处理数组中的每个元素,并过滤元素,该函数中包含两个参数,第一个是当前数组元素的值,一个是当前数组元素的下标,即元素索引值。此函数应返回一个布尔值。另外,此函数可设置为一个字符串,当设置为字符串时,将视为“lambda-form”(缩写形式?),其中 a 代表数组元素,i 代表元素索…
2014-12-29T16:00:12Z · 编程语言 · 评论(0)
PHP无限极分类 非递归
废话不多说:直接代码,把下面的代码访问以下在本地 <?php $arr = array( array('id' => '3', 'name' => "上海", 'parid' => 4,'lev'=>4), array('id' => '4', 'name' => "上海1", 'parid' => 5,'lev'=>3), array('id' => '5', 'name' => "上海2", 'parid' => 6,'lev'=>2), array('id' => '6', 'name' => "上海3", 'parid' => 0,'lev'=>1), array('id' => '…
2014-12-25T17:11:46Z · 编程语言 · 评论(0)
yII2 邮件发送
1.在配置文件mail.php 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.163.com', 'username' => '15618380091@163.com', 'password' => '*******', 'port' => '25', 'encryption' => 'tls', ], 'messageConfig'=>[ 'charset'=>'UTF-8', 'from'=>['15…
2014-11-25T17:43:00Z · 编程语言 · 评论(0)
yII2 多语言设置
yii2的多语言个yii1几乎类似 1.设置默认语言:在mail.php配置文件加上:'language'=>'zh-CN' 2.多语言切换 html代码 <a href="<?php echo Yii::$app->urlManager->createUrl(['/ebay/user/language','lang'=>'zh-CN']);?>">中文</a> <a href="<?php echo Yii::$app->urlManager->createUrl(['/ebay/user/language','lang'=>'en']);?>">英文</a> controller代码 /…
2014-11-25T16:47:49Z · 编程语言 · 评论(0)
Yii2.0中实现规划任务
1.在 console/controllers 文件夹下创建一个把握器 <?php namespace console\controllers; use yii\console\Controller; /** * Test controller */ class TestController extends Controller { public function actionIndex() { echo "runnning success"; } //参数测试 public function actionSend($name) { echo "welcome to " . $name; }…
2014-11-25T11:27:37Z · 编程语言 · 评论(0)
Yii2.0 对数据库 查询的一些简单的操作
User::find()->all(); 此方法返回所有数据; User::findOne($id); 此方法返回 主键 id=1 的一条数据(举个例子); User::find()->where(['name' => '小伙儿'])->one(); 此方法返回 ['name' => '小伙儿'] 的一条数据; User::find()->where(['name' => '小伙儿'])->all(); 此方法返回 ['name' => '小伙儿'] 的所有数据; User::findBySql('SELECT * FROM user')->all();此方法是用 sql 语句查询 user…
2014-11-03T21:55:42Z · 编程语言 · 评论(0)
yii2-gridview中让关联字段带搜索和排序功能
要求: 要在订单(Order)视图的gridview中显示出客户(Customer)姓名,并使其具有与其它字段相同的排序和搜索功能。 数据库结构 订单表order含有字段customer_id 与 客户表customer的id字段关联 首先确保在Order Model中包含以下代码: 一定要是get开头的,用的时候,把get去掉 public function getCustomer() { return $this->hasOne(Customer::className(), ['id' => 'customer_id']); } 第一步: 在OrderSearch添加一个$custome…
2014-11-03T21:53:37Z · 编程语言 · 评论(0)
yii CDbCriteria常用的方法
注:$c = new CDbCriteria();是ActiveRecord的一种写法,使ActiveRecord更加灵活,而不是手册中DAO(PDO)和Query Builder。 criteria常用的sql拼接方式 $criteria = new CDbCriteria; //函数方式 $criteria->addCondition("id=1"); //查询条件,即where id = 1 $criteria->addInCondition('id', array(1,2,3,4,5)); //代表where id IN (1,23,,4,5,); $criteria->addNot…
2014-11-02T14:25:43Z · 编程语言 · 评论(0)
yii 常用的对数据库处理方式
1 .Select: 常用几种方法 // find the first row satisfying the specified condition $post=Post::model()->find($condition,$params); // find the row with the specified primary key $post=Post::model()->findByPk($postID,$condition,$params); // find the row with the specified attribute values $post=Post::model()…
2014-11-02T14:18:49Z · 编程语言 · 评论(0)