PHP按千分位格式化数字 number_format

看到有用正则处理的,就查了下手册,看到这个方法。 其实 PHP 自带的好多方法都可以实现我们的一些功能,遇到问题,可以先看看手册。 number_format 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $number = 1234.56; // english notation (default) $english_format_number = number_format($number); // 1,235 // French notation $nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234,56 $number = 1234.5678; // english notation without thousands seperator $english_format_number = number_format($number, 2, '.', ''); // 1234.57 money_format

July 19, 2013

6.cn的两个PHP面试题

读取一个文件,将其 Base64 编码,每 76 个字符加一个换行 1 echo chunk_split(base64_encode(@file_get_contents(__FILE__))); 写一个函数,参数为$n,生成一个数组,其元素为1~$n,各元素位置随机排列,不得重复 1 2 3 $arr=range(1, $n); shuffle($arr); print_r($arr);

May 25, 2013

PHP安装MongoDB驱动

linux 1 2 3 4 5 6 7 8 wget -c https://github.com/mongodb/mongo-php-driver/archive/master.zip unzip master.zip cd mongo-php-driver-master phpize \#### php-config路径 ./configure --with-php-config=/usr/local/php/bin/php-config make && make install 然后在 php.ini 文件里面 添加 1 extension=mongo.so; 重启 PHP,OK。 windows 下载驱动包 https://s3.amazonaws.com/drivers.mongodb.org/php/index.html 如:https://s3.amazonaws.com/drivers.mongodb.org/php/php_mongo-1.3.7.zip 解压,将与自己 PHP 版本一致的 dll 文件复制到 {php}\ext 文件夹下({php}是你安装 php 的文件夹)。 如:php_mongo-master-5.4-vc9.dll 在 php.ini 文件中 添加 extension ,注意文件名: 1 extension=php_mongo-master-5.4-vc9.dll 重启 PHP,OK。

April 17, 2013

linux 下安装MongoDB

1、下载 到官网下载 相应的版本(32bit, 64bit)http://www.mongodb.org/downloads 2、配置 1 2 3 4 tar zxvf mongodb-linux-i686-x.x.x.tgz (xxx是相应版本号) cp mongodb-linux-i686-x.x.x /usr/local/mongodb cd /usr/local/mongodb mkdir /usr/local/mongodb/data 在 /usr/local/mongodb/ 下新建一个配置文件(文本),mongo.conf,将配置信息写入到文件,如下: port=27017 dbpath=/usr/local/mongodb/data logpath=/usr/local/mongodb/mongo.log pidfilepath=/usr/local/mongodb/mongo.pid directoryperdb=true logappend=true auth=true 相关 mongodb 的配置参数请看 Mongodb 启动命令 mongod 参数说明 https://mrasong.com/a/mongodb-config 3、启动 mongodb 1 /usr/local/mongodb/bin/mongod - f /usr/local/mongodb/mongo.conf --fork

April 17, 2013

windows下安装MongoDB

windows 下安装 MongoDB 1、下载 到官网下载 相应的版本(32bit, 64bit)http://www.mongodb.org/downloads 2、配置 解压下载下来的 MongoDB 包 mongodb-win32-i386-x.x.x.zip 到自己的目录,如 E:\\Mongo。 新建一个配置文件(文本),mongo.conf,将配置信息写入到文件,如下: port=27017 dbpath=E:\\Mongo\data logpath=E:\\Mongo\mongo.log pidfilepath=E:\\Mongo\mongo.pid directoryperdb=true logappend=true auth=true 相关 mongodb 的配置参数请看 Mongodb 启动命令 mongod 参数说明 https://mrasong.com/a/mongodb-config 3、启动 mongodb 打开 cmd,运行 E:\\Mongo\bin\mongod -f E:\\Mongo\mongodb.conf --install ,将 mongodb 添加至 windows 服务。 运行 net start mongodb ,即可启动。 注意: install 参数若写入到 config 文件中时,将不能正常启动服务,linux 当中的 fork 写入到 config 文件可以后台运行。

April 17, 2013

Mongodb启动命令mongod参数说明

mongod 的主要参数有: 基本配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 --quiet # 安静输出 --port arg # 指定服务端口号,默认端口 27017 --bind_ip arg # 绑定服务 IP,若绑定 127....

April 17, 2013

用sina weibo图片服务器做免费图床

先看一张新浪微博的图片: https://ww1.sinaimg.cn/large/759ca81bjw1e3lszmrg8yj.jpg https://ww2.sinaimg.cn/bmiddle/759ca81bjw1e3lszmrg8yj.jpg https://ww3.sinaimg.cn/small/759ca81bjw1e3lszmrg8yj.jpg https://ww4.sinaimg.cn/thumbnail/759ca81bjw1e3lszmrg8yj.jpg 这个图片地址由三个部分组成 https://{host}/{size}/{filename} {host}: CDN 图片服务器 host,ww1.sinaimg.cn,ww2.sinaimg.cn,ww3.sinaimg.cn,ww4.sinaimg.cn,这四个当中的任何一个。 {size}: 尺寸。thumbnail|缩略,quare|方形缩略图, thumb180, wap360, small|小图, bmiddle|中图,mw600|600, wap720, mw720|720, mw1024|1024, large|原图。 {filename}: 上传至图片服务器上唯一的文件名,后缀名 .jpg 使用 1、打开微博,上传图片 2、在图片上点击右键,“复制图片网址”: 3、复制下来的地址就像上面的地址一样,将 {size} 替换成你想要的大小,就可以使用了。 注意:多图上传时,会把几个图片合并成一张图片,方法一样。 代理 1、后端程序,以 PHP 为例 #sinaimg.php 1 2 $path = empty($_GET['path']) ? "" : $_GET['path'] ; header("location: https://ww".rand(1,4)."sinaimg.cn/".ltrim($path,"\/")); 使用时 sinaimg.php?path=large/759ca81bjw1e3lszmrg8yj.jpg ,会自动跳转到随机的一个图片服务器。 2、 nginx rewrite,使图片更像自己服务器的。 1 2 3 4 5 6 #assets.your.domain server { listen 80; server_name assets.your.domain; return 301 https://ww1.sinaimg.cn$request_uri; } 然后就可以用 http://assets....

April 12, 2013

一句代码让js实现PHP的rand方法

1 2 3 function rand(a, b) { return (parseInt(Math.random().toString().substr(2)) % (b - a + 1)) + a; }

April 10, 2013

百度mp3接口(baidu mp3 api)

新接口请看:百度 mp3 接口(新) 1、通过关键词,获取列表。 http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&ie=utf-8&word=<word>&format=<format> 参数: word: "歌曲名", //歌曲名 encodeURI format: "json", //返回数据格式,xml | json,默认xml callback: "Pub.music.searchResult", //固定值,返回jsonp格式 如 xml 格式: http://mp3.baidu.com/dev/api/?tn=getinfo&ct=0&word=%E6%B5%81%E6%B5%AA%E8%AE%B0&ie=utf-8&format=xml 返回: 1 2 3 4 5 6 7 8 9 10 <res> <song><![CDATA[流浪记]]></song> <song_id><![CDATA[38233821]]></song_id> <singer><![CDATA[杨宗纬]]></singer> <album><![CDATA[我是歌手 第十一期]]></album> <singerPicLarge><![CDATA[http://qukufile2.qianqian.com/data2/pic/36218335/36218335.jpg]]></singerPicLarge> <singerPicSmall><![CDATA[http://qukufile2.qianqian.com/data2/pic/36218344/36218344.jpg]]></singerPicSmall> <albumPicLarge><![CDATA[]]></albumPicLarge> <albumPicSmall><![CDATA[]]></albumPicSmall> </res> ...

April 9, 2013

最全weather.com.cn天气网各接口地址

1、省份列表: http://weather.com.cn/data/city3jdata/china.html 2、根据省 ID 获取市(地区)列表: http://weather.com.cn/data/city3jdata/provshi/.html http://weather.com.cn/data/listinfo/city.xml id = 省份ID (101 + 两位数字01~34) sid = 省份ID 后两位 如: http://weather.com.cn/data/city3jdata/provshi/10111.html 1 2 3 4 5 6 7 8 9 10 11 12 13 { "01": "西安", "02": "咸阳", "03": "延安", "04": "榆林", "05": "渭南", "06": "商洛", "07": "安康", "08": "汉中", "09": "宝鸡", "10": "铜川", "11": "杨凌" } 如: http://weather.com.cn/data/listinfo/city11.xml 1101|西安,1102|咸阳,1103|延安,1104|榆林,1105|渭南,1106|商洛,1107|安康,1108|汉中,1109|宝鸡,1110|铜川,1111|杨凌 3、根据市(地区)ID 获取县列表: http://weather.com.cn/data/city3jdata/station/<id>.html http://weather.com.cn/data/listinfo/city<sid>.xml id = 省份ID + 市(地区)ID sid = 省份ID 后两位 + 市(地区)ID 如:http://weather....

April 2, 2013