Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
7b796343
Commit
7b796343
authored
Apr 17, 2009
by
Richard Mansfield
Browse files
Don't chop utf-8 strings in the middle of a character
parent
8630f436
Changes
1
Show whitespace changes
Inline
Side-by-side
htdocs/lib/web.php
View file @
7b796343
...
...
@@ -2367,11 +2367,11 @@ function str_shorten($str, $maxlen=100, $truncate=false, $newlines=true) {
$str
=
html_entity_decode
(
$str
);
// no things like only take up one character
// take the first $length chars, then up to the first space (max length $length + $extra chars)
if
(
$truncate
&&
strlen
(
$str
)
>
$maxlen
)
{
$str
=
substr
(
$str
,
0
,
$maxlen
-
3
)
.
'...'
;
if
(
$truncate
&&
mb_
strlen
(
$str
,
'UTF-8'
)
>
$maxlen
)
{
$str
=
mb_
substr
(
$str
,
0
,
$maxlen
-
3
,
'UTF-8'
)
.
'...'
;
}
if
(
strlen
(
$str
)
>
$maxlen
)
{
$str
=
substr
(
$str
,
0
,
floor
(
$maxlen
/
2
)
-
1
)
.
'...'
.
substr
(
$str
,
-
(
floor
(
$maxlen
/
2
)
-
2
));
if
(
mb_
strlen
(
$str
)
>
$maxlen
)
{
$str
=
mb_
substr
(
$str
,
0
,
floor
(
$maxlen
/
2
)
-
1
,
'UTF-8'
)
.
'...'
.
mb_
substr
(
$str
,
-
(
floor
(
$maxlen
/
2
)
-
2
)
,
mb_strlen
(
$str
,
'UTF-8'
),
'UTF-8'
);
}
$str
=
nl2br
(
hsc
(
$str
));
// this should be ok, because the string gets checked before going into the database
...
...
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