Skip to content

Commit

Permalink
Use mb_substr() for correct abbreviation of non-ASCII characters (#651)
Browse files Browse the repository at this point in the history
When using substr() or another method to reduce a string to/by 1 byte,
many UTF-8 characters are lost (displayed as � ). Switching to mb_substr() fixes this.
  • Loading branch information
xalt7x authored Sep 16, 2024
1 parent aeb1ce5 commit e7c1ab1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Candidates.php
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ public function __construct($instanceName, $siteID, $parameters, $misc = 0)
'filter' => 'candidate.web_site'),

'Key Skills' => array('select' => 'candidate.key_skills AS keySkills',
'pagerRender' => 'return substr(trim($rsData[\'keySkills\']), 0, 30) . (strlen(trim($rsData[\'keySkills\'])) > 30 ? \'...\' : \'\');',
'pagerRender' => 'return mb_substr(trim($rsData[\'keySkills\']), 0, 30) . (strlen(trim($rsData[\'keySkills\'])) > 30 ? \'...\' : \'\');',
'sortableColumn' => 'keySkills',
'pagerWidth' => 210,
'filter' => 'candidate.key_skills'),
Expand Down
8 changes: 4 additions & 4 deletions lib/StringUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,24 +499,24 @@ public static function makeInitialName($firstName, $lastName,

if ($lastCommaFirst)
{
$firstInitial = $firstName[0] . '.';
$firstInitial = mb_substr($firstName, 0, 1) . '.';

if (strlen($lastName) > $maxLength)
{
return ucwords(
substr($lastName, 0, $maxLength) . ', ' . $firstInitial
mb_substr($lastName, 0, $maxLength) . ', ' . $firstInitial
);
}

return ucwords($lastName . ', ' . $firstInitial);
}

$lastInitial = $lastName[0] . '.';
$lastInitial = mb_substr($lastName, 0, 1) . '.';

if (strlen($firstName) > $maxLength)
{
return ucwords(
substr($firstName, 0, $maxLength) . ' ' . $lastInitial
mb_substr($firstName, 0, $maxLength) . ' ' . $lastInitial
);
}

Expand Down

0 comments on commit e7c1ab1

Please sign in to comment.