Jump to content

Archived

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

Woodburn2006

Text

Recommended Posts

when getting a block of text from a database, is there anyway of making the txt appear in 2 columns?

so that half of the text is in one column and then the rest is in the next column

thanks

Share this post


Link to post
Share on other sites
Are you talking about an HTML table column or a database column?

Ronald  ;D

Share this post


Link to post
Share on other sites
im gettin from a single column from the database then want to spread it across 2 html columns

is there any way of splitting the output into 2 variables? that way it would be easy to do it

Share this post


Link to post
Share on other sites
My suggestion is just to split the variable into 2 parts using the length.
Calculate the middle of the string, do a strpos to find the 1st blank and calculate the length of the first part and the second part.

Do a [code]<tr><td>$first_part</td<td>$second_part</td></tr>[/code] at you are done.

Ronald  ;D

Share this post


Link to post
Share on other sites
Just a sample (the table border set to 1 so you can see it is actually split):
[code]
<?php
$string = "This is a text stringandisnow to be split in 2 parts";
$length = strlen($string)/2;
$start=strpos(substr($string,$length),' ');
echo '<table border="1">';
echo '<tr><td>'.substr($string,0,$length+$start).'</td><td>'.substr($string,$length+$start).'</td></tr>';
echo '</table>';
?>[/code]

Ronald  ;D

Share this post


Link to post
Share on other sites
and wunt it leave a word half in 1 column & 1/2 in the other

Share this post


Link to post
Share on other sites
That is exactly why you must look for the first blank character after the first half of the text (using strpos)! So you don't split words but only on word boudary.

Ronald  ;D

Share this post


Link to post
Share on other sites
by using the method show above, is there any way of putting the 2 results as variables? i have tried but seem to get nowhere

Share this post


Link to post
Share on other sites
[code]<?php
$string = "This is a text stringandisnow to be split in 2 parts";
$length = strlen($string)/2;
$start=strpos(substr($string,$length),' ');

$part1 = substr($string,0,$length+$start);
$part2 = substr($string,$length+$start);
[/code]

Share this post


Link to post
Share on other sites

×

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.