Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-25-2012, 04:52 PM   PM User | #1
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
function to split a description into lines of 68 chars long

Im just wondering if anyone can help me out. Iv been trying to figure this out all day.
I have these variables

PHP Code:
$booking['occasion']
$booking['date']
$booking['venue'
and I want to make a description out of them like this.

$description = "Deposit for supplying a DJ for an $occasion on the
$date in the $venue";

I want to display the description over 3 or 4 lines in a pdf file like this

PHP Code:
$pdf->writeHTMLCell(1395'20''125'$line1''11true'L'true);
$pdf->writeHTMLCell(1395'25''125'$line2''11true'L'true);
$pdf->writeHTMLCell(1395'30''125'$line3''11true'L'true);
$pdf->writeHTMLCell(1395'35''125'$line4''11true'L'true);
$pdf->writeHTMLCell(1395'40''125'$line5''11true'L'true); 
I want to wrap the description to a next line after every 68 characters but only want to wrap after completed words

Can anyone help me create a function to split the desicprtion into 3 or 4 lines so far I have this code which I know is along the lines that I want.

PHP Code:
$description "Deposit for suppling a DJ and Equipment for a $occasion on the 
$date in $venue"
;
$decriptionLength strlen($description);
if(
$decriptionLength <= 68){
    
$line1 $description;    
}
elseif(
$decriptionLength 68)
{
    
$line1 substr($description068);
    
$line2 substr($description68136);

This code will wrap the text even in the middle of a word so I don’t want this.
I know this might be a lot to ask but if anyone can come up with some code I would be greatly appreciated.

Last edited by kevinkhan; 11-25-2012 at 05:00 PM..
kevinkhan is offline   Reply With Quote
Old 11-25-2012, 07:18 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Use wordwrap and explode:
PHP Code:
$wrapped wordwrap($description68PHP_EOLtrue);
$aLines explode(PHP_EOL$wrapped);
$iLines count($aLines);
$increase 5;
for (
$i 0$j 25$i $iLines; ++$i$j += $increase)
{
    
$pdf->writeHTMLCell(1395$j125$aLines[$i], ''11true'L'true);

Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:21 PM.


Advertisement
Log in to turn off these ads.