HighDots Forums  

a small question about PHP

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss a small question about PHP in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rG]Courage-D-
 
Posts: n/a

Default a small question about PHP - 06-01-2004 , 09:54 AM






i need some help, im a real noob, i want to show only 30 words and then add
..... at the end (so when more then 30 words it wil be cut of with....)

my problem is that i dont know how to put this code:

if(strlen($source) > 30) $message = str_pad($source, 30, "...", STR_PAD_RIGHT);

into this table:

<td width="279" align="left" valign="top" bgcolor="#BDBDBD">

<p class="Description"><?php echo $row_Animation['description']; ?></p>

</td>


Reply With Quote
  #2  
Old   
Martin Purcell
 
Posts: n/a

Default Re: a small question about PHP - 06-01-2004 , 10:05 AM






try this:

<td width="279" align="left" valign="top" bgcolor="#BDBDBD">
<p class="Description"><?php echo
(strlen($row_Animation['description']) > 30) ?
substr($row_Animation['description'], 0, 30)."..." :
$row_Animation['description']; ?></p>
</td>

the best place to ask php advice is #php on EFNet, you can pretty much
guarantee that there'll be someone who can help you in there with anything


rG]Courage-D- wrote:
Quote:
i need some help, im a real noob, i want to show only 30 words and then add
.... at the end (so when more then 30 words it wil be cut of with....)

my problem is that i dont know how to put this code:

if(strlen($source) > 30) $message = str_pad($source, 30, "...", STR_PAD_RIGHT);

into this table:

td width="279" align="left" valign="top" bgcolor="#BDBDBD"

p class="Description"><?php echo $row_Animation['description']; ?></p

/td


Reply With Quote
  #3  
Old   
Gary White
 
Posts: n/a

Default Re: a small question about PHP - 06-01-2004 , 10:52 AM



On Tue, 1 Jun 2004 13:54:53 +0000 (UTC), "rG]Courage-D-"
<webforumsuser (AT) macromedia (DOT) com> wrote:

Quote:
i need some help, im a real noob, i want to show only 30 words and then add
.... at the end (so when more then 30 words it wil be cut of with....)

my problem is that i dont know how to put this code:

if(strlen($source) > 30) $message = str_pad($source, 30, "...", STR_PAD_RIGHT);
Do you want 30 words, or 30 characters? If, as your code above suggests,
you want 30 characters, then Martin's code will do that for you. If, on
the other hand, you want 30 words, like your question suggests, try it
this way:

<?php
$s=$row_Animation['description'];
$a=explode(" ",$s);
if (count($a)>30){
$a=array_slice($a,0,30);
$s=join($a, " ")."...";
}
?>

Quote:
td width="279" align="left" valign="top" bgcolor="#BDBDBD"
p class="Description"><?php echo $s; ?></p
/td

Gary


Reply With Quote
  #4  
Old   
rG]Courage-D-
 
Posts: n/a

Default Re: a small question about PHP - 06-01-2004 , 01:49 PM



Originally posted by: Newsgroup User
try this:

<td width="279" align="left" valign="top" bgcolor="#BDBDBD">
<p class="Description"><?php echo
(strlen($row_Animation['description']) > 30) ?
substr($row_Animation['description'], 0, 30)."..." :
$row_Animation['description']; ?></p>
</td>

the best place to ask php advice is #php on EFNet, you can pretty much
guarantee that there'll be someone who can help you in there with anything


rG]Courage-D- wrote:
Quote:
i need some help, im a real noob, i want to show only 30 words and then add
.... at the end (so when more then 30 words it wil be cut of with....)

my problem is that i dont know how to put this code:

if(strlen($source) > 30) $message = str_pad($source, 30, "...",
STR_PAD_RIGHT);

into this table:

td width="279" align="left" valign="top" bgcolor="#BDBDBD"

p class="Description"><?php echo $row_Animation['description']; ?></p

/td

Thanks, a lot. that was the awnser



Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.