Jump to content

(more...) for articles


alexcmm

Recommended Posts

Hello all,

Let me begin by saying... I'm an idiot...

 

ok, I'd like to know how to have a "more..." function kick in if an entry is is longer than X characters. I don't even know what that's called so I can search for it.

 

Is it easy? If you can't tell me how, can you tell me what it's called so I can go find it on my own?

 

Thanks!  ~AlexCMM

Link to comment
https://forums.phpfreaks.com/topic/42678-more-for-articles/
Share on other sites

If you want it to pop up while it's being typed... you will need some fancy Javascript or something...

 

If you want it to have a "more..." when someone is reading it, then you could probably do something similar with pagination...

 

maybe just a go to article link that will take you to the full article, and only read in the first x number of characters for the current page...

Link to comment
https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207071
Share on other sites

Heres my version...

 

function limit_string($string, $charlimit){
   if(substr($string,$charlimit-1,1) != ' ')   {
       $string = substr($string,'0',$charlimit);
       $array = explode(' ',$string);
       array_pop($array);
       $new_string = implode(' ',$array);
       return $new_string.'...';
   }else{   
      return substr($string,'0',$charlimit-1).'...';
   }
  }

Link to comment
https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207200
Share on other sites

Thanks all... I found the "strlen" function right after I posted this. But thanks for the fast replies.

 

I thought I'd share my code just incase it helps anyone else.

<?
MYSQL_CONNECT($host, $user, $pass) OR DIE("DB connection unavailable");
@mysql_select_db( "$database") or die( "Unable to select database"); 

$query="SELECT * FROM $table ORDER BY id DESC limit 1";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$announ=mysql_result($result,$i,"announ");

$short = substr ($announ, 0 , 155);  \\ 0 marks where to begin, 155 marks which character to end with
$count = strlen($short);
$link = "... <i><a href='main_announ.php?id=$id'>more<span class=\"text_small\">>></span></a></i>";

if($count < "155") {
echo $short;
} else {
echo $short . $link;
}
$i++;
}

?>				

Link to comment
https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207204
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.