vitao.web Posted July 18, 2010 Report Share Posted July 18, 2010 Sveiki! Ir kods: <?php if($i==0){ $style = 'latest'; // ko ierakstit saja sadala lai teksts pec 350 simboliem (paraditos...) }else{ $style ='newest'; // ko ierakstit saja sadala lai tekst pec 200 simboliem (paradidtos...) } echo " <div class='".$style."'> <div class='ntitle'>".$rez['title']."</div> <div class='ndate'> date: ".$rez['newdate']."</div> <div class='nmessage'>".$rez['message']."</div> // un kas butu jaizdara seit? <br/> <div> <a class='nlink' title='".$rez['title']."' href=?news=".$rez['id']."?cat=".$rez['cat']."> <font face='Tahoma' style='font-size: 8pt'>Read more</font> </a> </div> <br/> </div>"; $i++; } ?> Kā panākt šo te visu? Jo pēc idejas ir viens garais teksts kam ir 350 simboli ( radas ka galvenais ) un tad sanos ir tris mazaki teskti kam ir 200 simboli. Tāds ir mans mērķis, bet nu nemacesu pats izveidot ta :( Paldies par palīdzību! Quote Link to comment Share on other sites More sharing options...
vitao.web Posted July 18, 2010 Author Report Share Posted July 18, 2010 function ShortenText($text) { // Change to the number of characters you want to display $chars = 25; $text = $text." "; $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text."..."; return $text; } Zinu ka ar šo to var izdarit, bet kā darīt ja ir 2 izmēri? Quote Link to comment Share on other sites More sharing options...
Val Posted July 18, 2010 Report Share Posted July 18, 2010 izlabo funkciju un $chars padod kā otro parametru. Quote Link to comment Share on other sites More sharing options...
vitao.web Posted July 18, 2010 Author Report Share Posted July 18, 2010 izlabo funkciju un $chars padod kā otro parametru. nu bet ka lai define katram ( style= 'latest' text 350 simboli style='newest' 100 simbolu garu ) Quote Link to comment Share on other sites More sharing options...
daGrevis Posted July 18, 2010 Report Share Posted July 18, 2010 Neaizmirstiet par mb_... =D Quote Link to comment Share on other sites More sharing options...
Valis Posted July 18, 2010 Report Share Posted July 18, 2010 nu bet ka lai define katram ( style= 'latest' text 350 simboli style='newest' 100 simbolu garu ) function ShortenText($text, $chars = 25) { // default = 25 $text = $text." "; $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text."..."; return $text; } Quote Link to comment Share on other sites More sharing options...
vitao.web Posted July 18, 2010 Author Report Share Posted July 18, 2010 function crop_string($string, $max_length, $end='...'){ if ( mb_strlen($string) > $max_length ){ $string = mb_substr($string, 0, $max_length); return $string.$end; } return $string; } Kur man kludina? kadel kad noradu $max_lenght = 250; vai vienalga kadu citu lielumu man radas tikai ...? Quote Link to comment Share on other sites More sharing options...
Valis Posted July 18, 2010 Report Share Posted July 18, 2010 (edited) function crop_string($string, $max_length, $end='...'){ if ( mb_strlen($string) > $max_length ){ $string = mb_substr($string, 0, $max_length); return $string.$end; } return $string; } Kur man kludina? kadel kad noradu $max_lenght = 250; vai vienalga kadu citu lielumu man radas tikai ...? Sāc ar vārda pareizrakstību - max_length . Un vari padot šādi: crop_string('string', 100); Edited July 18, 2010 by Valis Quote Link to comment 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.