Mouse Posted June 15, 2006 Share Posted June 15, 2006 Mental Block time…Quoting the first 50 words… more>>Ok so it has something to do with count() but I can’t get my head around it… I want to quote the first 50 words of an article in the link to that page but how can I pull the first 50 words and put them along with a “more>>” link at the end???Mouse Quote Link to comment https://forums.phpfreaks.com/topic/12051-quoting-the-first-50-words%E2%80%A6-more/ Share on other sites More sharing options...
joquius Posted June 15, 2006 Share Posted June 15, 2006 preg_replace ("/([\w]{50})/", "$1 more\>\>", $text);but I'm a bit rusty on reg expressions so check it first Quote Link to comment https://forums.phpfreaks.com/topic/12051-quoting-the-first-50-words%E2%80%A6-more/#findComment-45826 Share on other sites More sharing options...
Mouse Posted June 15, 2006 Author Share Posted June 15, 2006 [!--quoteo(post=384101:date=Jun 15 2006, 09:03 AM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 15 2006, 09:03 AM) [snapback]384101[/snapback][/div][div class=\'quotemain\'][!--quotec--]preg_replace ("/([\w]{50})/", "$1 more\>\>", $text);but I'm a bit rusty on reg expressions so check it first[/quote]i was thinking along the lines of[code]if(strlen($srchrow["desc"])>75){ $srchrow["desc"]=substr($srchrow["desc"],0,75)."..."; } [/code]but this counts letters not words... any ideas?Mouse Quote Link to comment https://forums.phpfreaks.com/topic/12051-quoting-the-first-50-words%E2%80%A6-more/#findComment-45829 Share on other sites More sharing options...
wildteen88 Posted June 15, 2006 Share Posted June 15, 2006 Prehaps [a href=\"http://uk.php.net/manual/en/function.str-word-count.php\" target=\"_blank\"]str_word_count[/a] may be what you're looking for? Quote Link to comment https://forums.phpfreaks.com/topic/12051-quoting-the-first-50-words%E2%80%A6-more/#findComment-45844 Share on other sites More sharing options...
Prismatic Posted June 15, 2006 Share Posted June 15, 2006 [code]<?php$MyString = "The move by Nielsen and sister company Netratings, upon whose research TV networks, Web sites and advertisers rely for setting advertising rates, could bring major changes to the TV industry as people increasingly watch shows outside the home or on computers, mobile devices and cell phones. The new testing, which also looks at viewership in restaurants and expands the use of electronic metering to smaller TV markets, could also dramatically change the way viewership figures are tallied and might result in major shifts in the way advertising dollars are spent and received. The new plan by Nielsen, which is owned by information provider VNU, is called Anytime Anywhere Media Measurement, or A2/M2. It will roll out over the next several years, starting with test programs as soon as this summer.";$MyLink = "http://www.google.com";function TrimStr($String, $Limit){ $StringArr = explode(" ", $String); for($i=0; $i <= $Limit-1; $i++){ $TrimStr .= $StringArr[$i] ." "; } return $TrimStr;}$ShortString = TrimStr($MyString, 50);echo $ShortString ." <a href='". $MyLink ."' alt='More!'>More»</a>";?>[/code]Usage should be easy to understand Quote Link to comment https://forums.phpfreaks.com/topic/12051-quoting-the-first-50-words%E2%80%A6-more/#findComment-45848 Share on other sites More sharing options...
litebearer Posted June 15, 2006 Share Posted June 15, 2006 or...[code]// get the first xx words for the teaser $contents="some text";$max_words=50;if (count(explode(" ", $contents))> $max_words) { $contents = substr($contents, 0, strnpos($contents, " ", $max_words)); } $contents = $contents . "...More>"; [/code](part of ... [a href=\"http://www.nstoia.com/toh/technical/teasers/)\" target=\"_blank\"]http://www.nstoia.com/toh/technical/teasers/)[/a]Lite... Quote Link to comment https://forums.phpfreaks.com/topic/12051-quoting-the-first-50-words%E2%80%A6-more/#findComment-45850 Share on other sites More sharing options...
Mouse Posted June 15, 2006 Author Share Posted June 15, 2006 Most excelent... many thanksMouse [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/12051-quoting-the-first-50-words%E2%80%A6-more/#findComment-45858 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.