-1

I am concatenating two sub-strings with an ellipsis (...) added at the end of the first sub-string. However I want this elipsis to be removed after the concatenation. Is this possible via a script or other means, Thanks:

<?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 deletes the elipsis like requested, however does not fully work in my situation: The code below works however, The first sub-string is repeated. I need a way to remove the first sub-string.

<?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);
?>
4

2 回答 2

0

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

substring 1 from 0 until length(A) - 3

substring 2 from length(A) until total length

您也可以使用正则表达式并将“...”替换为“”,但这可能会删除其他可能不需要的“...”。

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

于 2012-05-28T21:12:07.363 回答
0

简单的

<?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;";

?>
于 2012-05-28T21:16:11.177 回答