0

Hi guys.

Im trying to write a php Read More script for my blog. What I want is to be able to render the first two paragraphs and then give a Read More link for the rest of the article. I've tried doing it myself and failed. If someone can point me towards a tutorial or script then I would be forever grateful.

Edited by mtho

4
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by LastMitch
0

I 've tried a few but can's get them to work the way i want. Is it possible to get this function to only render 2 paragraphs if there is more than 2?

function substrws( $text, $len=750 ) { 

    if( (strlen($text) > $len) ) { 

        $whitespaceposition = strpos($text," ",$len)-1; 

        if( $whitespaceposition > 0 ) 
            $text = substr($text, 0, ($whitespaceposition+1)); 

        // close unclosed html tags 
        if( preg_match_all("|<([a-zA-Z]+)>|",$text,$aBuffer) ) { 

            if( !empty($aBuffer[1]) ) { 

                preg_match_all("|</([a-zA-Z]+)>|",$text,$aBuffer2); 

                if( count($aBuffer[1]) != count($aBuffer2[1]) ) { 

                    foreach( $aBuffer[1] as $index => $tag ) { 

                        if( empty($aBuffer2[1][$index]) || $aBuffer2[1][$index] != $tag) 
                            $text .= '</'.$tag.'>'; 
                    } 
                } 
            } 
        } 
    } 

    return $text; 
} 
0

@mtho

I 've tried a few but can's get them to work the way i want. Is it possible to get this function to only render 2 paragraphs if there is more than 2?

Did you write this script? I feel you didn't write this script. You just want to modify it but I don't see any errors meaning any effort of trying to make it work! It's so clean.

I'm a bit confused you mention that you just try to write PHP code but the example is in OOP or Classes and Objects. Are you using any PHP mainframe?

I'm just starting to learn OOP on my own.

You can also used AJAX which is in JQuery http://api.jquery.com/jQuery.get/ to render that file.

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.