Jump to content


Photo

Text


  • Please log in to reply
10 replies to this topic

#1 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 02 August 2006 - 10:24 AM

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

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 02 August 2006 - 10:26 AM

Are you talking about an HTML table column or a database column?

Ronald  ;D
RTFM is an almost extinct art form, it should be subsidized.

#3 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 02 August 2006 - 10:31 AM

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

#4 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 02 August 2006 - 10:38 AM

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
<tr><td>$first_part</td<td>$second_part</td></tr>
at you are done.

Ronald  ;D
RTFM is an almost extinct art form, it should be subsidized.

#5 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 02 August 2006 - 10:45 AM

im quite new so could you please tell me how to split the text into 2 variables please?

#6 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 02 August 2006 - 11:07 AM

Just a sample (the table border set to 1 so you can see it is actually split):
<?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>';
?>

Ronald  ;D
RTFM is an almost extinct art form, it should be subsidized.

#7 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 02 August 2006 - 11:13 AM

and wunt it leave a word half in 1 column & 1/2 in the other
I am a PHP Guru, ask me questions if you want to

#8 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 02 August 2006 - 11:21 AM

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
RTFM is an almost extinct art form, it should be subsidized.

#9 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 02 August 2006 - 11:36 AM

cool, works fine, thanks alot

#10 Woodburn2006

Woodburn2006
  • Members
  • PipPipPip
  • Advanced Member
  • 214 posts

Posted 04 August 2006 - 11:08 AM

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

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 August 2006 - 11:24 AM

<?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);

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users