本文整理汇总了PHP中str::limit_chars方法的典型用法代码示例。如果您正苦于以下问题:PHP str::limit_chars方法的具体用法?PHP str::limit_chars怎么用?PHP str::limit_chars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::limit_chars方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: title_slug
/**
* Returns a URL Safe Title Slug, limited to the specified characters
*
* @param string title
* @param int limit (default 25)
* @return string url safe slug
*/
public static function title_slug($title, $limit = 25)
{
return preg_replace("/([_+]|_)\$/", "", str::limit_chars(inflector::underscore(str::strip_all_but(strtolower($title), "a-z0-9 \\_")), $limit, ""));
}
示例2: trace_string
/**
* Returns a stacktrace in the form of a string
*/
public static function trace_string($trace)
{
$string = "";
// Setup the stack trace
$string .= Eight_Exception::trace_string_line("Stack trace:");
$string .= Eight_Exception::trace_string_line("");
$x = 0;
foreach (Eight_Exception::trace($trace) as $i => $step) {
$msg_line = "#" . str_pad($x, 2, "0", STR_PAD_LEFT) . " ";
if ($step['file']) {
$source_id = $error_id . 'source' . $i;
$msg_line .= Eight_Exception::debug_path($step['file']) . '(' . $step['line'] . "): ";
} else {
$msg_line .= "{" . __('PHP internal call') . "}: ";
}
$msg_line .= $step['function'] . '(';
$print_able_args = array();
if ($step['args']) {
$args_id = $error_id . 'args' . $i;
foreach ($step['args'] as $arg) {
$arg_name = "";
if (is_object($arg)) {
$arg_name = get_class($arg);
} else {
if (is_array($arg)) {
$arg_name = "Array(" . count($arg) . ")";
} else {
if (is_null($arg)) {
$arg_name = "NULL";
} else {
if (is_string($arg)) {
$arg_name = $arg;
} else {
$arg_name = strval($arg);
}
}
}
}
$arg_name = preg_replace("#\\s+#", " ", $arg_name);
$print_able_args[] = str::limit_chars($arg_name, 50, "");
}
}
$msg_line .= implode(", ", $print_able_args);
$msg_line .= ")";
$string .= Eight_Exception::trace_string_line($msg_line);
$x++;
}
return $string;
}
示例3: add_line
function add_line($str)
{
echo " | " . str_pad(str::limit_chars($str, $_ENV['box_width'] - 4, ""), $_ENV['box_width'] - 4, " ") . " |\n";
}