Jump to content
php.lv forumi

cut text


ziedinjsh

Recommended Posts

sveiki!

īsti nesaprotu kas pa problēmu. Izmantoju šādu teksta saīsinātāju:


function cutText($string, $limit, $break=".", $pad="..."){

 if(strlen($string) <= $limit) return $string;


 if(false !== ($breakpoint = strpos($string, $break, $limit))) {
   if($breakpoint < strlen($string) - 1) {
     $string = substr($string, 0, $breakpoint) . $pad;
   }
 }

 return $string;
}


 

teksts saīsinās.. it kā viss notiek, bet pārējie div kur tiek izvadīta informācija ir ielīduši pirmajā div, bet kad neizmantoju teksta saīsinātāju viss ir savās vietās!

 

datu izvadīšana


if($page==""){
$news = mysql_query("SELECT * FROM news ORDER BY id DESC")or die(mysql_error());

while($data = mysql_fetch_array($news)){

$news_text = cutText($data['news'],750);


if(empty($data['image'])){
$photo = "<img src='misc/no-image.jpg' class='image'>";
}else{
$photo = "<img src='images/small/".$data['image']."' class='image'>";
}

echo "
<div class='news'>
<div class='newstext'>
".$photo."<span class='title'>".$data['title']."<span class='date'>".$data['date']."</span></span><br><span class='content'>".$news_text." <a href='index.php?page=read&id=".$data['id']."'>Read more</a></span><br>
<span class=''>".$data['views']." views</span>
<div class='fix'></div>
</div>

</div>
<div class='shadow'></div>
";
}

Edited by ziedinjsh
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...