我正在切割一根绳子,以便用更长的绳子取出来。效果很好。
如果字符串包含一些HTML标签,那么如何在标签内部不会发生剪切?
$input = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores <a href="bla.html">Klick.</a> et ea rebum. Stet clita <a href="bla.html">Klick.</a> kasd gubergren, no sea takimata <a href="bla.html">Klick.</a> sanctus est Lorem ipsum dolor sit amet.'
$last_space = strrpos(substr($input, 0, $length), '.');
$trimmed_text = substr($input, 0, $last_space);