Woodburn2006 Posted August 2, 2006 Share Posted August 2, 2006 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 columnthanks Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/ Share on other sites More sharing options...
ronverdonk Posted August 2, 2006 Share Posted August 2, 2006 Are you talking about an HTML table column or a database column?Ronald ;D Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67736 Share on other sites More sharing options...
Woodburn2006 Posted August 2, 2006 Author Share Posted August 2, 2006 im gettin from a single column from the database then want to spread it across 2 html columnsis there any way of splitting the output into 2 variables? that way it would be easy to do it Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67739 Share on other sites More sharing options...
ronverdonk Posted August 2, 2006 Share Posted August 2, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67743 Share on other sites More sharing options...
Woodburn2006 Posted August 2, 2006 Author Share Posted August 2, 2006 im quite new so could you please tell me how to split the text into 2 variables please? Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67746 Share on other sites More sharing options...
ronverdonk Posted August 2, 2006 Share Posted August 2, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67751 Share on other sites More sharing options...
Chetan Posted August 2, 2006 Share Posted August 2, 2006 and wunt it leave a word half in 1 column & 1/2 in the other Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67752 Share on other sites More sharing options...
ronverdonk Posted August 2, 2006 Share Posted August 2, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67755 Share on other sites More sharing options...
Woodburn2006 Posted August 2, 2006 Author Share Posted August 2, 2006 cool, works fine, thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-67759 Share on other sites More sharing options...
Woodburn2006 Posted August 4, 2006 Author Share Posted August 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-69072 Share on other sites More sharing options...
AndyB Posted August 4, 2006 Share Posted August 4, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/16312-text/#findComment-69078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.