/** * 规范访问重写请求Url */ protected function formatRequestURI() { //访问主域名 if ($this->scriptUrl == '/') { return true; } //双//等处理 if (String::exist($this->scriptUrl, '//')) { $this->scriptUrl = preg_replace('/\\/+/is', '/', $this->scriptUrl); } // 重写请求Url以横杠结尾时处理 if (String::substr($this->scriptUrl, -1, 1) == '/') { $this->scriptUrl = String::substr($this->scriptUrl, 0, -1); } //有更改过scriptUrl,重新定位 if ($this->scriptUrl != Param::getScriptUrl()) { $queryString = Param::getQueryString(); Header::redirect($this->scriptUrl . ($queryString ? '?' . $queryString : '')); } return true; }
/** * 将路由组件转换到控制器方法 * * eg. add-discuss=>addDiscuss * * @param string $string路由组件 */ public static function mapRouteSegToMethod($string) { if (!String::exist($string, self::ROUTE_URL_SEP)) { return $string; } $segInfo = explode(self::ROUTE_URL_SEP, $string); $result = array(array_shift($segInfo)); //第一个首字符大写 foreach ($segInfo as $part) { $result[] = ucfirst($part); } return implode('', $result); }
private function test() { $string = <<<bbb <h1 class="title">6月14日【上海】开源中国 OSC 源创会第 25 期 现在报名»</h1> <h2 class="title">6月14日【上海】开源中国 OSC 源创会第 25 期 现在报名»</h2> <b color=green onclick="fdasfdsa">fdafdasf</b> <b style="fdsafa">fdafdasf</b> <b style="fdsafsda" src='fdfd' color="red">fdafdasf</b> <font color="red">font code</font> <img src="fdasfdas" onclick="fdasfdsa"> <Script>alert(1)</Script> <p>关于开源访谈</p> <P>关于开源访谈</P> <p> </p> <p> </p> <p> </p> <ul class="topic-list clearfix"> <li class="thumbnail"> <a href="http://iyunlin/zjgs"><img src="/static/image/nopic/100.gif"></a> <div class="caption" title="浙江工商"><a href="http://iyunlin/zjgs">浙江工商</a></div> </li> <li class="thumbnail"> <a href="http://iyunlin/FriendSter"><img src="/static/image/nopic/100.gif"></a> <div class="caption" title="交友"><a href="http://iyunlin/FriendSter">交友</a></div> </li> <li class="thumbnail"> <a href="http://iyunlin/topic/49"><img src="/static/image/nopic/100.gif"></a> <div class="caption" title="新生"><a href="http://iyunlin/topic/49">新生</a></div> </li> </ul> <p> <br />【作者简介】<br />栗元峰,开源爱好者。从iOS应用开发、cocos2d-iphone游戏开发到cocos2d-x游戏开发,参与了appstore排行榜单第一的《全民英雄》的开发,和其他多款上线成功项目。目前供职于http://9miao.com,专注于开源跨平台移动应用引擎CrossApp的开发。</p> <p><br /> <br />【软件简介】<br />CrossApp是一款免费、开源、跨平台的移动应用开发引擎,使用C++开发,基于OpenGL ES 2.0渲染,可以帮助所有开发者快速的开发出跨平台的原生移动应用,支持导出包括IOS和Android等。</p> <table> <tbody> <tr> <td>这是表格</td> <td>这是表格</td> <td>这是表格</td> <td>这是表格</td> <td>这是表格</td> <td>这是表格</td> <td>这是表格</td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </tbody> </table> bbb; echo BlockTextFormator::format($string) . '<br></br>'; echo '<pre>' . String::htmlEncode(BlockTextFormator::format($string)) . '</pre>'; }
/** * 密码关键信息隐藏,隐藏中间的密码 * * @param string $password 密码信息 */ public static function censorPassword($password) { if (empty($password)) { return false; } $length = \HuiLib\Helper\String::strlen($password); if ($length < 6) { return '******'; } return \HuiLib\Helper\String::substr($password, 0, 2) . str_repeat('*', $length > 10 ? 6 : $length - 4) . \HuiLib\Helper\String::substr($password, -2, 2); }
private function test() { echo 'Default charset:' . String::getDefaultCharset() . "\n"; echo String::iconv('中国人', 'UTF-8', 'GBK') . "\n" . "\n"; echo String::strlen('中国人') . "\n"; }
/** * 把键值转换成嵌套数组值 * * 数组 + 运算符附加右边数组元素,但是不会覆盖重复的键值。 * * @param string $key * @param string $value */ private function buildNestArray($key, $value, $parent = array()) { if (String::exist($key, self::KEY_SEP)) { $keyInfo = explode(self::KEY_SEP, $key); $valueArray = array(); $keyNow = array_shift($keyInfo); if (!isset($parent[$keyNow])) { $parent[$keyNow] = array(); } //递归从第一级创建,加法运算有效 $parent[$keyNow] += self::buildNestArray(implode('.', $keyInfo), $value, $parent[$keyNow]); } else { $parent[$key] = $value; } return $parent; }
/** * 发送一个Get请求 * @param string $url 请求网址 * @param array $param 请求参数 */ protected function getUrl($url, $param = array()) { if ($param && is_array($param)) { $url = $url . (String::exist($url, '?') ? '&' : '?') . http_build_query($param); } return $this->request($url); }