Php 通过计算回显的字符数来拆分回显,添加可变内容然后继续回显

Php split echo by counting characters echoed, add variable content and then keep echoing

需要我的 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"; 

但这只是回应了我文本的第一行。

终于得到这个解决方案:

$n=0;

$var="Texto largo mayor a 64 caracteres que complica mi utilizacion de una infografia en svg, ya que este lenguaje no acepta wrappers para el texto. Era muy lindo para ser verdad.";

$ts= mb_strwidth($var);

//Ahora defino una variable que cuenta el texto que queda por imprimir. 
$aimprimir=mb_strwidth($var);

if ($ts>64){

    while ($aimprimir>64):
    //mientras reste por imprimir un texto de largo mayor que 64....
    echo mb_strimwidth($var,$n,70,"<br/>");
    $aimprimir=$aimprimir-64;
    $n=$n+65;
    endwhile;

    //si lo que resta por imprimir es menor o igual a 64 entonces imprimalo...
    echo mb_strimwidth($var,$n,$aimprimir,"<br/>");

}

else {

echo "$var";

}