Page 1 of 1

Read More Link

Posted: Wed Dec 10, 2008 11:49 am
by madristaa
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


hello friends,

i have developed a php script which displays the news on the page. Even i have created the Read more link for the all those news. The problem is I want to display the whole sentence than the Read more links should appear.

Right now its showing up like..

Hi this is....[read more]

But i want the display like

Hi this is test. [read more].

The sentence should complete than the Read more link should come up. It should not be incomplete sentence than Read more link.

The coding is

Code: Select all

$length=strlen($row['newstext']);
                                if($length>250)
                                {
                                $posstr= strpos($row['newstext'],' ', 250);
                                 echo ' <span class="event" id="news">'.substr($row['newstext'],0,$posstr).'
                                  ... <a href="../news.php?newsid='.$row['newsid'].'" class="read">[read more...]</a></span>';
                                }
                                else
                                {
                                    echo ' <span class="event" id="news">'.$row['news_text'].'
                                        </span>';
 
                                }
 
 

I hope you have understand my problem.

Thanks in advance


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Read More Link

Posted: Wed Dec 10, 2008 2:17 pm
by requinix

Code: Select all

for ($posstr = 0; $posstr < 250; $posstr += strcspn($row["newstext"], "!.?", $posstr) + 1);
Replace your calculation of $posstr (line 4 in the code you posted) with that. Untested, but it should work.

Re: Read More Link

Posted: Wed Dec 10, 2008 3:54 pm
by madristaa
thanks man.......u solved my problem....thanks again...

Re: Read More Link

Posted: Wed Dec 10, 2008 5:04 pm
by madristaa
i have problem in your code....

if it contains any news contain information like 0.5 than it will stop at 0.

Example

The meeting is at 5.45. [read more]

than it will take

The meeting is at 5. [read more]

Re: Read More Link

Posted: Wed Dec 10, 2008 5:24 pm
by Jade
Make it search for a period followed by a space or <br> or <p> tag. That way it will skip over the period that's imbedded inside of a word.

Re: Read More Link

Posted: Wed Dec 10, 2008 5:28 pm
by madristaa
hi..can you explain me more briefly...i didnot understand....what changes should i make in my existing code?

Re: Read More Link

Posted: Thu Dec 11, 2008 8:27 am
by johnphilips
This was on my long list of todo's to figure out to improve my design. Glad I stumbled across this thread.