3
이러한 기능을 쓰려고합니다. 텍스트를 여러 열로 나누어야하며 출력은 유효한 html이어야합니다. 미개봉 (!!!) 닫기 태그 및 닫힌 태그가 없습니다. 여기 내 코드입니다 :문자열을 여러 열로 분할 (태그 인식)
function convert2columns($content = '', $columns = 2) {
$result = array();
$content = closetags($content);
$bodytext = array("$content");
$text = implode(",", $bodytext);
$length = strlen($text);
$length = ceil($length/$columns);
$words = explode(" ", $text);
$c = count($words);
$l = 0;
for ($i = 1; $i <= $columns; $i++) {
$new_string = "";
for ($g = $l; $g <= $c; $g++) {
if (strlen($new_string) <= $length || $i == $columns) {
if (in_array(substr(@$words[$g], $length - 1, 1), array(' ', '.', '!', '?')))
$new_string .= @$words[$g] . " ";
else {
$split = substr(@$words[$g], 0, $length - 1);
$lastSpace = strrpos($split, ' ');
if ($lastSpace !== false) {
$split = substr($split, 0, $lastSpace);
}
if (in_array(substr($split, -1, 1), array(','))) {
$split = substr($split, 0, -1);
}
$new_string .= $split . " ";
}
} else {
$l = $g;
break;
}
}
$result[] = $new_string;
}
return $result;
}
작동하지만, 2 열에 텍스트를 분할하려고 할 때, 나는 닫히지 않은 태그 첫 번째 열에 및 초에 개봉을 얻을. 이 문제를 해결하는 방법? 도움이 필요하다!
언제든지 문자열 함수 (또는 정규식)를 사용하여 HTML로 _anything_을 수행하면 문제가 발생할 수 있습니다. 즉, 얻은 것과 뭘 원하는지에 대한 견본 출력이 도움이 될 것입니다. :) – Herbert
closetags()는 무엇을합니까? 방법을 보여줄 수 있습니까? – Chris
안녕하세요, Zhlobopotam. 나는 방금 같은 문제에 대한 작업을 시작했고 도움이된다면 내 최종 솔루션을 공유하게되어 기쁘다. @ 크리스가 말했듯이 - closetags()는 무엇을합니까? – BaronGrivet