Jump to content

[SOLVED] flow text in 2 or more column


web_master

Recommended Posts

Here's a little script I wrote a while ago for doing just that:

 

<?php
$count=1;
$number_of_columns=2; //The required number of columns
while ($rowWork = mysql_fetch_array($resultWork)){   
    if ($count==1){
        echo "<tr>"; //Open the row
    }
    echo '<td valign="top">$row['column']</td>';
    if ($count==$number_of_columns){
        echo "</tr>"; //Close the row if we have reached the required number of columns
        $count=0; //Set the counter back
    }   
    $count++;
}
?>

[Edit] This is for display images etc over 2 columns but you should be able to modify it easly for text

another way:

 

<?php
$str = file_get_contents('lorem ipsum.txt');
$p = floor(strlen($str)/2);
$p = strpos($str, ' ', $p);   // find a space in middle of the text

echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, 0, $p)), '</div>';
echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, $p+1)),  '</div>';
?>

another way:

 

<?php
$str = file_get_contents('lorem ipsum.txt');
$p = floor(strlen($str)/2);
$p = strpos($str, ' ', $p);   // find a space in middle of the text

echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, 0, $p)), '</div>';
echo '<div style="float:left; width:45%; padding: 0 10px">', nl2br(substr($str, $p+1)),  '</div>';
?>

 

 

Barand, great! thnx!!!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.