Read More Link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
madristaa
Forum Newbie
Posts: 4
Joined: Wed Dec 10, 2008 11:41 am

Read More Link

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Read More Link

Post 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.
madristaa
Forum Newbie
Posts: 4
Joined: Wed Dec 10, 2008 11:41 am

Re: Read More Link

Post by madristaa »

thanks man.......u solved my problem....thanks again...
madristaa
Forum Newbie
Posts: 4
Joined: Wed Dec 10, 2008 11:41 am

Re: Read More Link

Post 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]
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Read More Link

Post 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.
madristaa
Forum Newbie
Posts: 4
Joined: Wed Dec 10, 2008 11:41 am

Re: Read More Link

Post by madristaa »

hi..can you explain me more briefly...i didnot understand....what changes should i make in my existing code?
johnphilips
Forum Newbie
Posts: 1
Joined: Thu Dec 11, 2008 8:18 am

Re: Read More Link

Post by johnphilips »

This was on my long list of todo's to figure out to improve my design. Glad I stumbled across this thread.
Post Reply