本文整理汇总了PHP中Illuminate\Support\Str::replaceLast方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::replaceLast方法的具体用法?PHP Str::replaceLast怎么用?PHP Str::replaceLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::replaceLast方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
public function handle($request, \Closure $next)
{
if (substr($request->getRequestUri(), -1) == '/') {
$baseUrl = $request->getBaseUrl();
// try to remove slash at the end of current url
$newUrl = substr($request->getRequestUri(), 0, -1);
if ($newUrl != $baseUrl) {
return redirect(Str::replaceLast($baseUrl, '', $newUrl));
}
}
return $next($request);
}
示例2: getAttribute
public function getAttribute($key)
{
if ($this->isUseImageMax()) {
$attribute = parent::getAttribute($key);
if (!$attribute) {
$profiles = config('imagemax.profiles', []);
foreach ($profiles as $profile => $options) {
if (Str::endsWith($key, $last = '_' . str_slug($profile, '_'))) {
$image = Str::replaceLast($last, '', $key);
if (in_array($image, $this->getImagableAttributes()) && $this->getAttribute($image)) {
return ImageMax::make($this->getAttribute($image), $options);
}
}
}
}
return $attribute;
}
return $this->thumbnailerGetAttribute($key);
}
示例3:
/**
* Replace the last occurrence of a given value in the string.
*
* @param string $search
* @param string $replace
* @param string $subject
* @return string
*/
function str_replace_last($search, $replace, $subject)
{
return Str::replaceLast($search, $replace, $subject);
}
示例4: function
*/
Str::macro('lastSegment', function ($string, $delimiter) {
return Str::segment($string, $delimiter, -1);
});
}
if (!Str::hasMacro('pop')) {
/**
* Pop off the last segment of a string based on a delimiter.
* Returns the remaining string.
*
* @param string $string
* @param string $delimiter
* @return string
*/
Str::macro('pop', function ($string, $delimiter) {
return Str::replaceLast($delimiter . Str::lastSegment($string, $delimiter), '', $string);
});
}
if (!Str::hasMacro('tease')) {
/**
* Shortens a string in a pretty way. Removes all double spaces and HTML.
* The string is concatenated with the moreTextIndicator.
*
* @param string $string
* @param int $length
* @param string $moreTextIndicator
* @return string
*/
Str::macro('tease', function ($string, $length = 200, $moreTextIndicator = '...') {
$string = preg_replace("/\\s+/", ' ', strip_tags(trim($string)));
if (strlen($string) <= $length) {
示例5: getUri
/**
* Determine the URI from the given method name.
*
* @param ReflectionMethod $routable
* @param string $path
*
* @return string
*/
public function getUri(ReflectionMethod $routable, $path)
{
$uri = $path . '/' . implode('-', array_slice(explode('_', Str::snake($routable->name)), 1)) . '/' . $this->getWildcards($routable);
$uri = str_replace('//', '/', $uri);
$uri = rtrim($uri, '/');
if (Str::endsWith($uri, 'index')) {
$uri = Str::replaceLast('index', '', $uri);
}
return $uri;
}