PHP

浏览模式: 标准 | 列表 | 图文
phpfog 要停止服务了。。。

phpfog 要停止服务了。。。

用phpfog也有两年了吧? 在上面也跑了2个应用,其中一个就是ucapi.com,其实说真的ucapi.com已经久不维护了。一来ucenter也很少有人在单独使用了。顺便,求收购。。。ucapi.com,HOHO。。

This is a reminder for PHP Fog users regarding the service’s discontinuation.

In order to focus our team and efforts on continuing to build a better solution for developers, we will be fully shutting down the PHP Fog platform in December (all free apps hosted on PHP Fog will be discontinued on December 21, 2012) and focusing solely on AppFog. As we move toward this final date, some services will be disabled along the way.

For more information plus resources to help you begin or complete your migration to AppFog, please read this blog post.

We are also going to be holding a webinar on migrating to AppFog from PHP Fog on December 6. For more information and to register for the migration webinar, please visit the AppFog University webinar page.

---现在正在想办法迁移到AppFOG,只是不知道APPFog以后会有多久也突然停了。

phpcloud怎么办?太麻烦

scope

scope

scope这个单词给人的遐想实在太多了。第一次熟悉它的时候是因为他在yii的AR中有个小小的位置,比如 默认的查询值 ,默认的更新值 等等,方便自己写代码,方便给其他人一些默认属性的设定。

前两天在和流年聊天时,他说,你应该是好久没有看过thinkphp了,thinkphp中也有类似功能了。然后给我一个网址:http://www.thinkphp.cn/info/176.html,这种命名范围是新加入的功能。看了一下,果然功能很类似,也挺不错。

都是实现了差不多类似的功能。其实在很久以前,我记得thinkphp就有default_update字段和default_insert字段的。还可以设默认值。现在查询也可以了。

thinkphp也算是天天在进度,用它写程序的人也越来越多了,最近相对较火的瀑布流程序:pinphp,就是基于thinkphp进行开发的,开发速度快,在国内拥有N多用户,但索取的人多,贡献的人少,这恐怕也是TP最近的现状了。

支持一下国内的框架。顺便,QuickPHP这个框架大家也可以先记一下。(http://quickphp.net/),是一哥们写的。断断续续写了N多年了。基本成型。

国内现在框架有N多了,好象是个写PHP的都有想框架的冲动,我老了,蛋定了,不写了。。。。

Yii 中 markdown 的用法

Yii 中 markdown 的用法

现在很多的文档都开始转向markdown了,其实在yii中很早就支持markdown的解析。用法也是相当的简单,有两种用法
1、在模版中

$this->beginWidget('CMarkdown', array('purifyOutput'=>true));
echo $content;
$this->endWidget();

2、在PHP代码中

$md = new CMarkdown;
echo $md->transform($str);

非常简单的使用。
写markdown文件的话,软件就多了,我是用Mou,一个非常小的软件,可以边写边预览,也能导成PDF。这个就方便了啦。。。
过两天网上找找markdown的一些CSS文件,以后博客什么的,就全部由markdown来处理,再也不占空间了。妈妈说,我再也不用担心学习了。哪里不懂就点哪里。

Yii自定义控制器

Yii自定义控制器

如果你的项目中有控制器需要共用,其实只需要在config/main.php中加入一小段代码即可实现:

'controllerMap'=>array(
'xxx'=>'ext.XxxController'
),

然后就可以直接调用了:index.php?r=xxx/index,即可以调用XxxController类中的activeIndex方法

这种适合在什么情况下呢?比如统一的出错处理类,这个就相对会比较方便,因为这样的代码会几乎一样。还有那种工具控制器,比如将数据导出成xls,可以写一个XlsController来处理它。

这样的控制器,一般来说适合用于不经权限控制的情况。

php手册说了,再多的Gcd也只能返回一个

php手册说了,再多的Gcd也只能返回一个

php手册里有一个函数叫做substr_count,是用来计算一个字符串在指定的字符串中出现的次数。

<?php
$text = 'This is a test';
echo strlen($text); // 14

echo substr_count($text, 'is'); // 2

// the string is reduced to 's is a test', so it prints 1
echo substr_count($text, 'is', 3);

// the text is reduced to 's i', so it prints 0
echo substr_count($text, 'is', 3, 3);

// generates a warning because 5+10 > 14
echo substr_count($text, 'is', 5, 10);


// prints only 1, because it doesn't count overlapped substrings
$text2 = 'gcdgcdgcd';
echo substr_count($text2, 'gcdgcd');
?>

最后一个例子很深刻的说明了,就算字符串重复再多,但是真要显示的话,也只显示一次,不重复计算。

xcache 发布3.0版本

xcache 发布3.0版本

xcache也开始追求版本号了?
1.x的时候几年都没变。2.01刚发布3个月立刻就是3.0了?
虽然官网上说这是一个里程碑式的更新,但谁能说的清?

更新倒是不少:

API Changes
========
* chg: proto array xcache_clear_cache(int type, [ int id = -1 ]). -1 means all cache splits
* new: proto array xcache_enable_cache(int type, [ int id = -1, [ bool enable = true ] ])
* new: proto array xcache_admin_namespace()
* new: proto array xcache_set_namespace(string namespace)

Ini Settings Changes
========
* new: xcache.disable_on_crash = Off
* new: xcache.coverager_autostart = On
* new: xcache.allocator = bestfit (no other option value yet)
* new: xcache.var_allocator = bestfit (no other option value yet)

ChangeLog
========
* closes #2: auto disable caching on crash
* closes #73: warn for improper PHP_FCGI_CHILDREN setting fcgi mode (>=PHP_5_3)
* closes #174: updates api to support "clear all cache"
* closes #198: support for caching protocol url
* closes #287: namespace support
* fixes #39: ini_set never work for xcache.coverager setting. use API instead
* code refactor
* uses extension= to load XCache. loading via zend_extension= is unsupported
* split XCache features into multiple sub modules
* updates XCache admin page
* adds an diagnosis module to give professional advise, accessable via htdocs pages
* cache can be enabled/disabled manually

反正,他们自我评价挺高的:XCache 3.0.0 released. Lots of improvements, bug fixes. This is a big new milestone refactoring most XCache code.

在首页的下载里面还写着:
2.1.x, unstable, devel, features
结果,3.0都Release了。。。
这年头。。。还能怎么办?

针对品鉴网的一些URL路由设置

针对品鉴网的一些URL路由设置

这篇文章又能当成开发文档,也能当成软文,所以,你们就将就着看吧。

yii框架中很早就支持路由功能了。所以,从那时候开始,很多人就开始将项目路由化,举例说明:
http://user.pinjian.net,访问用户中心
http://admin.pinjian.net 访问后台
http://xxxx.pinjian.net 访问Xxx
表面上这是一大堆 网站,其实很有可能是什么?只是一个控制器或者一个module罢了。
http://user.pinjian.net可能对应了什么?http://pinjian.net/user/index,很有可能就这样而已。
而对于yii来说,这个太简单了
在main.php(环境 变量设置中),针对urlManager的rules加入:

'urlManager' => array(
'urlFormat' => 'path',
'showScriptName'=>false,
'rules' => array(
'http://photo.pinjian.net/<action:\w+>'=>'image/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),

看看高亮的那一行,是不是很简单?
之前,有一篇博客介绍过的:http://www.neatstudio.com/show-1550-1.shtml,还篇比较详细

Unicode转换

其实只是一段很少的代码。

<?php
function uni_decode($s) {
preg_match_all('/\&\#([0-9]{2,5})\;/', $s, $html_uni);
preg_match_all('/[\\\%]u([0-9a-f]{4})/ie', $s, $js_uni);
$source = array_merge($html_uni[0], $js_uni[0]);
$js = array();
for($i=0;$i<count($js_uni[1]);$i++) {
$js[] = hexdec($js_uni[1][$i]);
}
$utf8 = array_merge($html_uni[1], $js);
$code = $s;
for($j=0;$j<count($utf8);$j++) {
$code = str_replace($source[$j], unicode2utf8($utf8[$j]), $code);
}
return $code;//$s;//preg_replace('/\\\u([0-9a-f]{4})/ie', "chr(hexdec('\\1'))", $s);
}

function unicode2utf8($c) {
$str="";
if ($c < 0x80) {
$str.=chr($c);
} else if ($c < 0x800) {
$str.=chr(0xc0 | $c>>6);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x10000) {
$str.=chr(0xe0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
} else if ($c < 0x200000) {
$str.=chr(0xf0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3f);
$str.=chr(0x80 | $c>>6 & 0x3f);
$str.=chr(0x80 | $c & 0x3f);
}
return $str;
}

$str='%u5927%u5BB6%u597D%uFF0C我是孤魂!<br />\u8FD9\u662F\u6D4B\u8BD5\u6587\u672C\uFF01';
echo uni_decode($str); // 大家好,我是孤魂!这是测试文本!
?>

这段代码以前也写过,而且,其实用的地方挺多,比如json的字符串(有些只是json处理了一下,但并不能完全转换,总不能强制变成json格式再转换吧?)
其实黑的很方便,而且这段代码在PHP手册中的注释里也出现过,但一下子找不到了,于是看到后就做了个备份罢了

06d4c679d916d33683edada6ce3ad182

version_compare

version_compare

在项目中遇到点小问题。。。
比如:1.4.0与1.4.1对比。还有1.2与1.21对比
在初期的时候,我都是直接使用version_compare来对比的,但这时候就出现了问题

在国人眼中,1.21其实是1.2的后续版本,它是比1.3小的一个版本。但。。。version_compare即不认的。它认为1.21>1.2,当然1.21也>1.3。。。
好纠结啊。。。

后面没办法,对于1.4.0这种用version_compare了。对于1.21的,直接浮点数来比较了。NND

以后对版本号还是需要有一个规划,不能乱写啊

利用curl上传文件

利用curl上传文件

利用php的curl库上传文件真的很方便
注意几点
1、只能是POST
2、可以不写头(平时的form有文件和无文件时发送的时候,)
3、postfields的时候,不要你傻傻的http_build_query,你越是这么做了。黑黑。。。就反而不一定对了
4、上传的文件用@来连接。
一个很小的例子

$formAction = 'http://xxx/xxx/xx.upload.php';
$postVals = array(
// /var/www/www.jpg 这个地址是绝对地址哦。可以让程序读取
// windows下面可能就是d:/xxx/xxx/xxx.jpg
'img'=>'@/var/www/xxx.jpg', //img就相当于表单中的<input type="file" name="img" />

);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $formAction); //登录地址
curl_setopt($ch, CURLOPT_POST, 1); //这是POST数据
curl_setopt($ch, CURLOPT_POSTFIELDS, ($postVals)); //http_build_query( $postData)); ,如果你真用http_build_query,不一定能成功。所以。。。还是有curl自己去组合吧
$res = curl_exec($ch);
curl_close($ch);

看看多简单,一下子就成功了