if(strlen($item->T03_PROMOTION_TITLE)>31) echo mb_substr($item->T03_PROMOTION_TITLE, 0,26, "UTF8"); else echo $item->T03_PROMOTION_TITLE;?>>>>>
<div class="bs_font16 ellipsis"><a class="" href="<?php echo appSettings::strWebURL.'/newsdetail/index.php?P=0&ID='.$item->T03_PROMOTION_ID.'&CBR='.$item->T03_PROMOTION_CATEGORY.'#main'?>"><?php if(mb_strlen($item->T03_PROMOTION_CONTENT, '8bit')>160) echo mb_substr( $item->T03_PROMOTION_CONTENT, 0, 51,"UTF8").'...'; elsecho$item->T03_PROMOTION_CONTENT;?>
In Japanese, 26 characters are displayed.
In English, 52 characters are displayed.
What kind of commands do you use for documents mixed in Japanese and English?
Could you tell me?
Thank you.
If you want to display two lines of characters, I think you can use a different approach.
Simply display 2 in the area and only your own area, and then disappear
.area{
height:2em;
overflow — hidden;
}
Browsers are likely to be limited, but CSS seems to be able to handle them.
https://tech.recruit-mp.co.jp/front-end/tips-ellipsis/
When counting by string, you have a lot to think about, so
I thought it would be easy to use css, so this is a suggestion.
I think I should solve it with CSS.
Replace half-width characters (ASCII) with a
, replace full-width characters (non-ASCII) with Aa
, and
The number of a
characters in 52 characters from the beginning is the approximate number of characters to be truncated from the beginning.
<?php
function abort ($title, $length)
{
$tmp = $title;
$tmp = preg_replace('/[\\x20-\\x7E]/iu', 'a', $tmp);
$tmp = preg_replace('/[^a]/iu', 'Aa', $tmp);
$tmp = substr($tmp,0,52);
$length = substr_count($tmp, 'a');
returnmb_substr($title, 0, $length, 'UTF-8');
}
$title='Confirmation test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
echo$title, PHP_EOL;
echo abort ($title, 52), PHP_EOL, PHP_EOL;
$title = 'testtesttesttesttesttestestestestestestestestestestestestestestestestest';
echo$title, PHP_EOL;
echo abort ($title, 52), PHP_EOL, PHP_EOL;
$title='Confirmation TestConfirmation TestConfirmation TestConfirmation TestConfirmation Test';
echo$title, PHP_EOL;
echo abort ($title, 52), PHP_EOL, PHP_EOL;
Results
%php abbreviate.php
Verification Test Test Test Verification Test Verification Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test
Verification Test Test Verification Test Verification Test Verification Test testte
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test.
test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test
Verification Test Verification Test Verification Test Verification Test Verification Test Verification Test
Confirmation Test Confirmation Test Confirmation Test Confirmation Test Confirmation Test Confirmation Test Confirmation
Non-ASCII characters and characters with half-width equivalent characters are not the intended behavior.
© 2024 OneMinuteCode. All rights reserved.