本文整理汇总了PHP中strings::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP strings::substr方法的具体用法?PHP strings::substr怎么用?PHP strings::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类strings
的用法示例。
在下文中一共展示了strings::substr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_str
function parse_str($str, $cfg)
{
// skip some shit
// $str = str_replace(array(' ',"'","`"),array(' ','"','"'),$str);
// support for 1 param
if (is_string($cfg)) {
$cfg = array($cfg => true);
}
// check param is fine
if (count(array_intersect_key($cfg, $this->_parse_options)) != count(array_keys($cfg))) {
$cfg_string = array();
foreach ($keys = array_keys($cfg) as $key) {
if (!isset($this->_parse_options[$key])) {
$cfg_string[] = $key;
}
}
$cfg_string = implode(', ', $cfg_string);
throw new validator_exception('Unknown cfg params ' . $cfg_string . ' in validator::parse_str', validator_exception::ERROR);
}
// strip tags
if (isset($cfg['strip_tags'])) {
$cfg['allowed_tags'] = is_string($cfg['strip_tags']) ? $cfg['strip_tags'] : false;
$str = strip_tags($str, $cfg['allowed_tags']);
}
// max length
if (!empty($cfg['max_length'])) {
$str = strings::substr($str, 0, $cfg['max_length']);
}
// sql escape
if (isset($cfg['sql_escape'])) {
if (class_exists('sql_db', 0)) {
// @todo different database types support?
$str = mysql_real_escape_string($str);
// $str = sql_db::sql_escape($str);
}
}
// Replaces \n -> <br>
// This is tidy issure - it will break <br/> instead of <br>
if (isset($cfg['nl2br'])) {
$str = str_replace("\n", "<br>", $str);
}
// Clean with tidy
if (isset($cfg['clean_html'])) {
$str = $this->clean_html($str);
}
return $str;
}
示例2: _is_route_matched
/**
* Check route matched to uri
* Extract params (only for regex <?Pname> routes)
*/
private function _is_route_matched($route, &$params)
{
$match = isset($route['match']) ? $route['match'] : false;
$uri = $this->_uri;
// wildcard: /url/blabla/*
if ($match) {
if ($match == '*') {
$match = '';
$uri = '';
} else {
if (strings::strpos($match, '*') !== false) {
$match = strings::substr($match, 0, strings::strpos($match, '*'));
$uri = strings::substr($uri, 0, strings::strlen($match));
}
}
}
return isset($route['regex']) && preg_match($route['regex'], $this->_uri, $params) && array_shift($params) || $match !== false && $uri == $match;
}
示例3: route
/**
* Try base route,
* otherwise try find out node
*
* @todo move stuff to controller
*/
function route($parts)
{
// Try abse routes
if (parent::route($parts)) {
return true;
}
$uri = implode('/', $parts);
$in_index = empty($parts);
if ($in_index) {
$this->render_index();
return true;
}
$comment_filter = $this->create_filter('sat.comment/modify');
$this->append_filter('comment_modify', $comment_filter);
if (!$comment_filter->match_uri($uri)) {
$comment_filter = null;
}
$pagination_filter = $this->create_filter('pagination');
// append filter for later use
$this->append_filter('pagination', $pagination_filter);
$pagination_filter->match_uri($uri);
// string(54) "14_dvigatel_mehanicheskaya_chast/klapanniy_zazor_2zzge"
$node_url = '/' . $uri;
if (strings::substr($node_url, -5) != loader::DOT_HTML) {
$node_url .= '/';
}
$this->_static_node_url = $node_url;
$c_site_id = $this->context->get_current_site_id();
$_item = $this->context->get_tree_item($c_site_id, $node_url, tf_sat::TREE_URL);
if (!$_item) {
throw new router_exception('Node not found', router_exception::NOT_FOUND);
}
/** @var sat_node_item $item */
$item = $this->context->get_node($_item['id']);
if (!$item) {
throw new router_exception('Node item not found', router_exception::NOT_FOUND);
}
core::dprint(array('Found node %d, %s ', $item->id, $item->title));
$tlayout = $item->get_template();
if (isset($tlayout['site']['order'])) {
$item->get_children_handle()->set_order($tlayout['site']['order']);
}
core::event('sat_route_before', $item);
/* pagination filter */
$page = $pagination_filter->get_start();
try {
$item->apply_children_filter($page);
} catch (collection_filter_exception $e) {
throw new router_exception($e->getMessage(), router_exception::NOT_FOUND);
}
$item->get_parent();
// load secondary, if not disabled
if (!isset($tlayout["site"]["item"]["deps"]) || $tlayout["site"]["item"]["deps"]) {
$item->with_deps(@$tlayout["site"]["item"]["deps"]);
$item->load_secondary(@$tlayout["site"]["item"]["deps"]);
}
$this->_current_node = $item;
// for comments bindings
$this->context->controller->set_current_item($item);
if ($comment_filter) {
$comment_filter->run();
}
/** @var tf_renderer */
$renderer = $this->context->renderer;
//
// template alternative layout {layout}.tpl
//
if ($tlayout['template']) {
$renderer->set_page_template($tlayout['template']);
}
core::event('sat_render_before', $item);
$renderer->current->node = $item->render();
$renderer->current->node_chain = $this->context->get_node_parents($item->id)->render();
$renderer->set_main_template(($tpl = $this->context->get_controller()->get_template()) ? $tpl : 'sat/node/item');
return true;
}