Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
42b0de48
Commit
42b0de48
authored
15 years ago
by
Laurent Destailleur
Browse files
Options
Downloads
Patches
Plain Diff
A more clever truncate function.
parent
304a83d6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
htdocs/lib/functions.lib.php
+5
-4
5 additions, 4 deletions
htdocs/lib/functions.lib.php
with
5 additions
and
4 deletions
htdocs/lib/functions.lib.php
+
5
−
4
View file @
42b0de48
...
...
@@ -943,7 +943,8 @@ function dolibarr_trunc($string,$size=40,$trunc='right',$stringencoding='')
}
/**
* \brief Truncate a string to a particular length adding '...' if string larger than length
* \brief Truncate a string to a particular length adding '...' if string larger than length.
* If length = max length+1, we do no truncate to avoid having just 1 char replaced with '...'.
* \param string String to truncate
* \param size Max string size. 0 for no limit.
* \param trunc Where to trunc: right, left, middle
...
...
@@ -962,7 +963,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='')
if
(
$trunc
==
'right'
)
{
$newstring
=
dol_textishtml
(
$string
)
?
dol_string_nohtmltag
(
$string
,
1
)
:
$string
;
if
(
dol_strlen
(
$newstring
,
$stringencoding
)
>
$size
)
if
(
dol_strlen
(
$newstring
,
$stringencoding
)
>
(
$size
+
1
)
)
return
dol_substr
(
$newstring
,
0
,
$size
,
$stringencoding
)
.
'...'
;
else
return
$string
;
...
...
@@ -970,7 +971,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='')
if
(
$trunc
==
'middle'
)
{
$newstring
=
dol_textishtml
(
$string
)
?
dol_string_nohtmltag
(
$string
,
1
)
:
$string
;
if
(
dol_strlen
(
$newstring
,
$stringencoding
)
>
2
&&
dol_strlen
(
$newstring
,
$stringencoding
)
>
$size
)
if
(
dol_strlen
(
$newstring
,
$stringencoding
)
>
2
&&
dol_strlen
(
$newstring
,
$stringencoding
)
>
(
$size
+
1
)
)
{
$size1
=
round
(
$size
/
2
);
$size2
=
round
(
$size
/
2
);
...
...
@@ -982,7 +983,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='')
if
(
$trunc
==
'left'
)
{
$newstring
=
dol_textishtml
(
$string
)
?
dol_string_nohtmltag
(
$string
,
1
)
:
$string
;
if
(
dol_strlen
(
$newstring
,
$stringencoding
)
>
$size
)
if
(
dol_strlen
(
$newstring
,
$stringencoding
)
>
(
$size
+
1
)
)
return
'...'
.
dol_substr
(
$newstring
,
dol_strlen
(
$newstring
,
$stringencoding
)
-
$size
,
$size
,
$stringencoding
);
else
return
$string
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment