-
-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathStr.php
More file actions
65 lines (57 loc) · 1.42 KB
/
Copy pathStr.php
File metadata and controls
65 lines (57 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Styde\Html;
class Str extends \Illuminate\Support\Str
{
/**
* Convert camel cases, underscore and hyphen separated strings to human
* format.
*
* @param $string
* @return string
*/
public static function title($string)
{
$stringr = $string[0].preg_replace('@[_-]|([A-Z])@', ' $1', substr($string, 1));
return ucfirst(strtolower($stringr));
}
/**
* Convert text links to HTML links.
*
* @param $text
*
* @return mixed
*/
public static function linkify($text)
{
return preg_replace(
'@(https?://[a-z0-9_./?=&-]+)@i',
'<a href="$1" target="_blank">$1</a>',
$text
);
}
/**
* Cuts a string but without leaving incomplete words and adding a $end
* string if necessary.
*
* @param $value
* @param $length
* @param string $end
*
* @return mixed|string
*/
public static function teaser($value, $length, $end = '...')
{
if (empty($value)) {
return '';
}
$value = strip_tags($value);
$value = preg_replace('/(\s+)/', ' ', $value);
$long = strlen($value);
if ($long <= $length) {
return $value;
}
$pos = strrpos($value, ' ', $length - $long);
$value = substr($value, 0, $pos ?: $length);
return $value.$end;
}
}