chrome Posted July 9, 2009 Share Posted July 9, 2009 Hello I'm having a difficulty locating a sample script that implements teaser. What I need is to display a specified amount of text on my website from a much larger group of text, then I want it to place a trailing ... [more]. I do not want it to show a partial word when the desire quantity is achieved eg. Imple instead of Implementation. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/165368-how-to-use-teaser-in-php4/ Share on other sites More sharing options...
WolfRage Posted July 9, 2009 Share Posted July 9, 2009 Well you need to get the data into a string with file_get_contents(). Then shorten it to the appropriate length using substr(). <?php $string=file_get_contents($file); $teaser=substr($string,0,200); echo $teaser.'...more'; //make this a link ?> Quote Link to comment https://forums.phpfreaks.com/topic/165368-how-to-use-teaser-in-php4/#findComment-872121 Share on other sites More sharing options...
litebearer Posted July 9, 2009 Share Posted July 9, 2009 Might look here also. http://www.wljol.com/toh/technical/teasers/index.php I have been moving things around, so the graphics on that page are 'messed-up'; however, the text, example and downloadable zip are all functional Quote Link to comment https://forums.phpfreaks.com/topic/165368-how-to-use-teaser-in-php4/#findComment-872123 Share on other sites More sharing options...
.josh Posted July 9, 2009 Share Posted July 9, 2009 WolfRage, your solution will cutoff words, which the OP said he does not want. A combo of wordwrap and explode should do the trick: $string = "some really long text"; $string = explode("[TEXTBREAK]",wordwrap($string,110,"[TEXTBREAK]")); // change 110 to whatever amount of chars $newString = $string[0] . "...<a href='somepage.php'>[more]</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/165368-how-to-use-teaser-in-php4/#findComment-872129 Share on other sites More sharing options...
WolfRage Posted July 9, 2009 Share Posted July 9, 2009 Nicely done Crayon, I had considered that, just felt I was giving him a nudge in the right direction with out presenting a complete solution. I perfer to nudge people along. I think they learn better that way. Quote Link to comment https://forums.phpfreaks.com/topic/165368-how-to-use-teaser-in-php4/#findComment-872198 Share on other sites More sharing options...
.josh Posted July 9, 2009 Share Posted July 9, 2009 Well I guess pointing someone in the right direction by showing him an example of what won't work is one way to do it, though not if you're telling him that's what he needs to do... Quote Link to comment https://forums.phpfreaks.com/topic/165368-how-to-use-teaser-in-php4/#findComment-872231 Share on other sites More sharing options...
WolfRage Posted July 9, 2009 Share Posted July 9, 2009 Ouch, didn't know we were trading shots. Quote Link to comment https://forums.phpfreaks.com/topic/165368-how-to-use-teaser-in-php4/#findComment-872295 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.