webForumDet fria alternativet

Funktion som delar upp innehållet i fler divar.

PHP

0 svar · 821 visningar · startad av Jesper T

Medlem sedan nov. 20017 144 inlägg
Frågan#1

Hej
Hittade en funktion (som jag gjorde om lite) här som delar upp en tabell i fler kolumner.

function wp_split2cols($colcontent, $columns) {
  $coloutput =  "";
  $bodytext = array("$colcontent");
  $text = implode(",", $bodytext); //prepare bodytext
  $length = strlen($text); //determine the length of the text
  $length = ceil($length/$columns); //divide length by number of columns
  $words = explode(" ",$text); // prepare text for word count and split the text into columns
  $c = count($words);
  $l = 0;
  for($i=1;$i<=$columns;$i++) {
    $new_string = "";
    $coloutput .= "<div class=\"divcols\">";
  for($g=$l;$g<=$c;$g++) {
    if(strlen($new_string) <= $length || $i == $columns)
    $new_string.=$words[$g]." ";
    else {
      $l = $g;
    break;
      }
     }
    $coloutput .= $new_string;
    $coloutput .= "</div>";
  }
  return $coloutput;
 }

Det som dock inte funkar är om den innehåller html på fel ställe. Då sabbas divarna. Tips?

264 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
120 ms — deklarationer (db)
0 ms — hämta statistik (cache)
129 ms — hämta tråd, inlägg och bilagor (db)
133 ms — ändringar (db)