随笔分类 - cakephp
cakephp framework
摘要:好像网上一直没有比较详细的中文资料来讲述如何使用cakephp来实现i18n。正好昨天被逼无奈的将代码中的提示中文化了一把,略有心得,简而志之。中文化cakephp有如下几步:1,在代码中使用__()函数。在需要进行中文化的地方使用__()函数,如下所示:__('This is the string i need to translate', true);将第2个参数置为ture,这样如果有相对应的翻译词条的话那么翻译过的词条将输出,否则会输出未翻译的词条。2,执行i18n task如果你的代码中存在__()函数的话,你就可以执行i18n task来进行代码扫描了。i18n t
阅读全文
摘要:好像网上一直没有比较详细的中文资料来讲述如何使用cakephp来实现i18n。正好昨天被逼无奈的将代码中的提示中文化了一把,略有心得,简而志之。中文化cakephp有如下几步:1,在代码中使用__()函数。在需要进行中文化的地方使用__()函数,如下所示:__('This is the string i need to translate', true);将第2个参数置为ture,这样如果有相对应的翻译词条的话那么翻译过的词条将输出,否则会输出未翻译的词条。2,执行i18n task如果你的代码中存在__()函数的话,你就可以执行i18n task来进行代码扫描了。i18n t
阅读全文
摘要:原本以为要自己写helper去截取中文字符串,没想到cakephp的Text helper类中已经提供了truncate方法。下面是truncate方法的原型。truncatetruncate(string $text, int $length=100, array $options)Cuts a string to the $length and adds a suffix with ‘ending’ if the text is longer than $length. If ‘exact’ is passed as false, the truncation will occur aft
阅读全文
摘要:众所周知php原生函数substr是不支持截取中文字符串的。下面的代码提供了多种截取php中文字符串的方法。1. 截取GB2312中文字符串<?php< ?php//截取中文字符串function mysubstr($str, $start, $len) { $tmpstr = ""; $strlen = $start + $len; for($i = 0; $i < $strlen; $i++) { if(ord(substr($str, $i, 1)) > 0xa0) { $tmpstr .= substr($str, $i, 2); $i++;
阅读全文

浙公网安备 33010602011771号