Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
da8c412d
Commit
da8c412d
authored
Jul 11, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deprecated text class.
parent
d0ba4719
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
98 deletions
+0
-98
text.php
system/text.php
+0
-98
No files found.
system/text.php
deleted
100644 → 0
View file @
d0ba4719
<?php
namespace
System
;
class
Text
{
/**
* Limit the words in a string. Word integrity will be preserved.
*
* @param string $value
* @param int $limit
* @param string $end
* @return string
*/
public
static
function
words
(
$value
,
$limit
,
$end
=
'…'
)
{
if
(
trim
(
$value
)
==
''
)
{
return
$value
;
}
preg_match
(
'/^\s*+(?:\S++\s*+){1,'
.
$limit
.
'}/'
,
$value
,
$matches
);
if
(
strlen
(
$value
)
==
strlen
(
$matches
[
0
]))
{
$end
=
''
;
}
return
rtrim
(
$matches
[
0
])
.
$end
;
}
/**
* Limit the number of characters in a string. Word integrity will be preserved.
*
* @param string $value
* @param int $limit
* @param string $end
* @return string
*/
public
static
function
characters
(
$value
,
$limit
,
$end
=
'…'
)
{
if
(
strlen
(
$value
)
<
$limit
)
{
return
$value
;
}
// Replace new lines and whitespace in the string.
$value
=
preg_replace
(
"/\s+/"
,
' '
,
str_replace
(
array
(
"
\r\n
"
,
"
\r
"
,
"
\n
"
),
' '
,
$value
));
if
(
strlen
(
$value
)
<=
$limit
)
{
return
$value
;
}
$out
=
''
;
foreach
(
explode
(
' '
,
trim
(
$value
))
as
$val
)
{
$out
.=
$val
.
' '
;
if
(
strlen
(
$out
)
>=
$limit
)
{
$out
=
trim
(
$out
);
return
(
strlen
(
$out
)
==
strlen
(
$value
))
?
$out
:
$out
.
$end
;
}
}
}
/**
* Censor a string.
*
* @param string $value
* @param array $censored
* @param string $replacement
* @return string
*/
public
static
function
censor
(
$value
,
$censored
,
$replacement
=
'####'
)
{
$value
=
' '
.
$value
.
' '
;
// Assume the word will be book-ended by the following.
$delim
=
'[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]'
;
foreach
(
$censored
as
$word
)
{
if
(
$replacement
!=
''
)
{
$value
=
preg_replace
(
"/(
{
$delim
}
)("
.
str_replace
(
'\*'
,
'\w*?'
,
preg_quote
(
$word
,
'/'
))
.
")(
{
$delim
}
)/i"
,
"
\\
1
{
$replacement
}
\\
3"
,
$value
);
}
else
{
$value
=
preg_replace
(
"/(
{
$delim
}
)("
.
str_replace
(
'\*'
,
'\w*?'
,
preg_quote
(
$word
,
'/'
))
.
")(
{
$delim
}
)/ie"
,
"'
\\
1'.str_repeat('#', strlen('
\\
2')).'
\\
3'"
,
$value
);
}
}
return
trim
(
$value
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment