jthunder Posted July 21, 2008 Share Posted July 21, 2008 Display 25 chars per line up to 4 lines only. I am doing a little array, but cant figure it out how to control to display the number of lines. I want to control the numer of lines to display to only 4 and 25 characters per line in a table. Somewhere here in the code below : $types_temp2[] = $categories[$value]['title']; I need to be able to limit the display to only 25 characters per line up to 4 lines only. Can you help? I did a few tricks but it mostly trunkates characters but continue to the last lines which often runs into about 20 lines. Thank you for your help. $types_temp = array(); $types_temp2 = array(); $types_temp3 = array(); $types_temp = explode(',', $info['project_types']); foreach ($types_temp as $value) { if(isset($categories[$value]['title'])) { $types_temp2[] = $categories[$value]['title']; } } $types_temp3 = implode(', ', $types_temp2); Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/ Share on other sites More sharing options...
mga_ka_php Posted July 22, 2008 Share Posted July 22, 2008 substr("your string", 0, 25); Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/#findComment-596062 Share on other sites More sharing options...
Stephen Posted July 22, 2008 Share Posted July 22, 2008 Well what regiemon posted is a starter (for one line). Try this: $_string="onehundredandonecharacter1111111111111111111111111111111111111111111111111111111111111111111111111120"; $_string_new=substr($_string,0,100); echo(wordwrap($_string_new,25,"<br />\n")); Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/#findComment-596064 Share on other sites More sharing options...
jthunder Posted July 22, 2008 Author Share Posted July 22, 2008 Hi Stephen, thanks for your reply. I tried using it but I am not that kind of programmer, I have some problems actually using it. Can you apply it to the above code please. thanks again, Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/#findComment-596089 Share on other sites More sharing options...
Stephen Posted July 22, 2008 Share Posted July 22, 2008 Well you aren't echoing anything anywhere so I assume it should be like this: $types_temp = array(); $types_temp2 = array(); $types_temp3 = array(); $types_temp = explode(',', $info['project_types']); foreach ($types_temp as $value) { if(isset($categories[$value]['title'])) { $types_temp2[] = $categories[$value]['title']; } } $types_temp3 = implode(', ', $types_temp2); $_string_new=substr($types_temp3,0,100); echo(wordwrap($_string_new,25,"<br />\n")); Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/#findComment-596117 Share on other sites More sharing options...
jthunder Posted July 22, 2008 Author Share Posted July 22, 2008 thanks mate. did not quite work. categories all went to the top of the page. lol Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/#findComment-596124 Share on other sites More sharing options...
mg.83 Posted July 22, 2008 Share Posted July 22, 2008 Where are you outputing this array? can you post the code? Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/#findComment-596131 Share on other sites More sharing options...
jthunder Posted July 22, 2008 Author Share Posted July 22, 2008 Code is above. The output is displayed at www.ContractorJoint.com under Category column. Good example is the project called "NOrth Berkeley" where the Job Categories are quite a lot. Thats why I need to trunkate the text as soon as it gets 4 lines already. Thanks, Link to comment https://forums.phpfreaks.com/topic/115911-control-number-of-lines-to-4-and-chars-per-line-25/#findComment-596133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.