Jump to content
php.lv forumi

Teksta saisinasana


vitao.web

Recommended Posts

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!

Link to comment
Share on other sites

    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?

Link to comment
Share on other sites

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;
    }

 

 

 

 

 

Link to comment
Share on other sites

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 ...?

Link to comment
Share on other sites

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 by Valis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...