ereadmore

Yii framework simple extension to shorten an html code.
4 followers

EReadMore

A simple extension to shorten an html code. - version 1.0 - author Dimitrios Mengidis tydeas.dr@gmail.com

Requirements

Description

This a common functionality found in blogs, where you see a part of an article and there is link usually named read more where get redirected to the full article. As an example you can check my blog.

Use

Simple case

In the view add:

<?php $this->beginWidget('application.extensions.EReadMore.EReadMore', array(
         'linkUrl'=>$data->url
     ));?>
     <div>
         <h1>EReadMore</h1>
        <p>A simple extension to shorten an html code.</p>
        <h2>Requirements</h2>
          <ul>
              <li><a href='php.net/manual/en/intro.dom.php' >DOMDocument</a></li>
          </ul>
     </div>
     <?php $this->endWidget(); ?>

Advanced use

Check the EReadMore code options to see what you can set.

Resources

Total 4 comments

#11538 report it
code4d1 at 2013/01/19 06:51am
read more..

for urgent solution to meet my need I make a read more with very simple php code strip_tags and substr

$desc = strip_tags(substr($data->description, 0, 200))."....";        
echo $desc;
echo CHtml::link('read more', array('view', 'id'=>$data->id),array('class'=>'btn btn-success btn-small'));

demo : www (dot) lowongankerja (dot) dewatatech (dot) com

#11378 report it
WebDevPT at 2013/01/10 05:12am
workaround

I manage to use this the "old fashion" way by using this code instead

$string = $data->content;
if(mb_strlen($string, 'utf-8') >= 700){
       $string = mb_substr($string, 0, 700 - 5, 'utf-8')." ".CHtml::link(CHtml::encode("read more..."), $data->url);
}
echo $string;

utf works ok and there's no need to use extensions. But still there's the problem with the cuts inside some tags like "ul". But it works.

#11377 report it
WebDevPT at 2013/01/10 04:12am
Utf problem

For this to work for a certain number of chars I'm using this, but still can't work around utf, any ideas?

if (strlen($data->content)<500) {
                              echo $data->content;
                            }
                            else
                            if (strlen($data->content)>500) {
                                $this->beginWidget('application.extensions.ereadmore.EReadMore', array('linkUrl'=>$data->url));
                                echo $data->content;
                                $this->endWidget();
                            }
                            else {
                              echo $data->content;
                            }                            
                            //echo $data->content;
                            $this->endWidget();
#11376 report it
WebDevPT at 2013/01/10 03:42am
Utf characters

After a few more tests i found out that this is actually working.

$this->beginWidget('application.extensions.ereadmore.EReadMore', array('linkUrl'=>$data->url));
    echo $data->content;
    $this->endWidget();

but the utf characters are not properly shown. Any ideas?

Leave a comment

Please to leave your comment.

Create extension