divinedesigns1 Posted November 24, 2013 Share Posted November 24, 2013 hey, i am trying to send a max about of words of 292 to be displayed on my site, and if the words are more than 292 i would like it to have a read more link at the end of it, soo i though it would be as simple as if($rows['decision'] > 292){ $more = '..read more';}else{ $more = '';} but that just add the read more to every section even if its less or more than 292 am i doing something wrong? Link to comment Share on other sites More sharing options...
Ingolme Posted November 24, 2013 Share Posted November 24, 2013 Check to see that $rows['decision'] has the value you expected it to have. Link to comment Share on other sites More sharing options...
Hadien Posted November 24, 2013 Share Posted November 24, 2013 (edited) I don't know regex sub patterns too well so I'm not sure if this will give you exactly what you've wanted. it should count the 1st 292 words and store them in $words[0], while the rest of the text will be stored in $words[1] (if the text has more than 292 words, otherwise the whole text will be in $words[0]). $wordcount = preg_match_all('/((?:s*w){292})(.*)/g',$rows['decision']),$words);if($wordcount !== false){ $section = $words[0]; if($wordcount >292){ $section .= " read more..."; }}else{ //error happened in pattern matching} Edited November 24, 2013 by Hadien Link to comment Share on other sites More sharing options...
thescientist Posted November 27, 2013 Share Posted November 27, 2013 (edited) hey, i am trying to send a max about of words of 292 to be displayed on my site, and if the words are more than 292 i would like it to have a read more link at the end of it, soo i though it would be as simple as if($rows['decision'] > 292){ $more = '..read more';}else{ $more = '';} but that just add the read more to every section even if its less or more than 292 am i doing something wrong? what is the value of $rows['decision']? Edited November 27, 2013 by thescientist Link to comment Share on other sites More sharing options...
aloniie Posted November 27, 2013 Share Posted November 27, 2013 PHP has a function for this, str_word_count($rows['decision']); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now