【发布时间】:2015-10-13 00:17:31
【问题描述】:
需要我的 php 代码来计算回显文本中的字符数。当这个计数达到 64 时,我需要它来回显“$something”并从它停止的地方继续回显。
此外,最好的情况是这段代码不应该裁剪完整的单词。
例如
-- 这个:
echo 'This is a huge string that i mean to crop acording to it\'s character\'s count. For every 64 characters including spaces i need it to echo some other thing in the middle';
-- 会这样结束:
echo 'This is a huge string that i mean to crop acording to it\'s ' . $something . 'character\'s count. For every 64 characters including spaces ' . $something . 'i need it to echo some other thing in the middle';
为了更好地理解...我需要这段代码来解决 SVG 文本不能被包装和对齐的事实。
你会使用 mb_strimwidth 吗?如何?
提前致谢!
--- 更新 1 - 我没有成功尝试
echo mb_strimwidth($row['resumen'], 0, 84, "$something");
echo mb_strimwidth($row['resumen'], 64, 64, "$something");
echo mb_strimwidth($row['resumen'], 128, 64, "$something");
--- 更新 2 - 部分成功!
$uno = substr($row['resumen'], 0, 64);
$dos = substr($row['resumen'], 64, 64);
$tres = substr($row['resumen'], 128, 64);
$suma = $uno . "</text><text>" . $dos . "</text><text>" . $tres;
echo "$suma";
但这只是呼应了我文字的第一行。
【问题讨论】:
-
您需要调查输出缓冲。在 Google 上搜索 ob_start。
-
我试过..... echo mb_strimwidth($row['resumen'], 0, 84, "$something"); echo mb_strimwidth($row['resume'], 64, 64, "$something"); echo mb_strimwidth($row['resume'], 128, 64, "$something");