alexcmm Posted March 14, 2007 Share Posted March 14, 2007 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 More sharing options...
interpim Posted March 14, 2007 Share Posted March 14, 2007 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 More sharing options...
alexcmm Posted March 14, 2007 Author Share Posted March 14, 2007 Pagination!! that's it! I do want the "link to another page" option... so I'll start looking around for pagination. Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207075 Share on other sites More sharing options...
Barand Posted March 14, 2007 Share Posted March 14, 2007 http://www.php.net/substr eg <?php $short = substr ($article, 0 , 50); // first 50 chars $link = "( <a href='article.php?article=$id'>more ...</a> )"; echo $short . $link; ?> Link to comment https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207076 Share on other sites More sharing options...
alexcmm Posted March 14, 2007 Author Share Posted March 14, 2007 That does look a little closer to waht I was thinking. Thanks Barand! Link to comment https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207101 Share on other sites More sharing options...
alexcmm Posted March 14, 2007 Author Share Posted March 14, 2007 ok, so what's the easiest way to do this? If there are more than X characters, echo [string with more link] Else, echo [string without more link] I'm just not very savy with PHP code yet... Thanks! Link to comment https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207192 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 If there are more than X characters, echo [string with more link] Else, echo [string without more link] if (strlen($string) > $xChar) { print "More Link here"; }else { print $string; } --FrosT Link to comment https://forums.phpfreaks.com/topic/42678-more-for-articles/#findComment-207196 Share on other sites More sharing options...
mbtaylor Posted March 14, 2007 Share Posted March 14, 2007 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 More sharing options...
alexcmm Posted March 14, 2007 Author Share Posted March 14, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.