删除省略号 (&helip;)子字符串串联后


Remove ellipsis (&helip;) after sub-string concatenation

我正在连接两个子字符串,并在第一个子字符串的末尾添加一个省略号 (...)。但是,我希望在连接后删除此省略号。这可以通过脚本或其他方式吗,谢谢:

<?php echo substr($post_text_result2, 0, 400) . "&hellip;";?><div id="second_post" class = "hidden"><?php echo substr($post_text_result2, 400, 5000);?></div>

str_replace按照要求删除省略号,但是在我的情况下不能完全工作:但是,下面的代码有效,第一个子字符串被重复。我需要一种方法来删除第一个子字符串。

<?php
$string = substr($post_text_result2, 0, 400) . "&hellip;"; 
echo $string;
?>
<div id="second_post" class = "hidden">
<?php       
$string= str_replace('&hellip;','',$string); echo $string;
echo $string;
echo substr($post_text_result2, 400, 5000);
?>

很容易

<?php
$string = substr($post_text_result2, 0, 400) . "&hellip;";
$string = str_replace('&hellip;','',$string);
?>

如果您希望省略号始终位于末尾,只需执行以下操作:

<?php
$string = substr($post_text_result2, 0, 400) . "&hellip;";
$string = str_replace('&hellip;','',$string) . "&hellip;";
?>

您可以存储第一个字符串 A 的长度,然后构建一个连接 2 个子字符串的新字符串:

substring 1 from 0 until length(A) - 3
substring 2 from length(A) until total length

您也可以使用正则表达式并替换"..."带有",但这可能会删除其他"..."这也许是不需要的。

抱歉没有代码,我不会PHP,但你知道怎么做;)