Jump to content

how to stop test from passing limit


divinedesigns1

Recommended Posts

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

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 by Hadien
Link to comment
Share on other sites

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 by thescientist
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...